草庐IT

ImplementsBaz

全部标签

c++ - 为什么 decltype(declval<T>().func()) 在 decltype(&T::func) 不工作的地方工作?

我试图检测成员函数baz()的存在在模板参数中:templatestructImplementsBaz:publicstd::false_type{};templatestructImplementsBaz:publicstd::true_type{};但它总是产生错误:structFoo{};structBar{voidbaz(){}};std::cout::value::value使用declval不过,调用该方法确实有效:templatestructImplementsBaz().baz())>:publicstd::true_type{};当然,现在这个只能检测一个baz具有0