0
我试图在函子上使用std::result_of
。为什么我会得到这些结果?std :: result_of在多态函子上
#include <typeinfo>
struct my_logical_not {
template<typename A>
bool operator()(const A &value) const {
return !value;
}
};
struct my_passthrough {
template<typename A>
A operator()(A &value) const {
return value;
}
};
int main() {
// this prints 'b':
std::cout << typeid(typename std::result_of<my_logical_not(int)>::type).name() << std::endl;
// this does not compile:
// main.cpp:24:66: error: ‘type’ in ‘class std::result_of<my_passthrough(int)>’ does not name a type
std::cout << typeid(typename std::result_of<my_passthrough(int)>::type).name() << std::endl;
return 0;
}
'my_passthrough(INT)'意味着你要(int)作为参数的右值,它不绑定到非常量左值引用 –
提示:这里不需要'typenames' –
我看到..将my_passthrough operator()更改为“operator() (const A&value)const“修正了它。谢谢! –