我有:
class A {
public:
B toCPD() const;
Run Code Online (Sandbox Code Playgroud)
和:
template<typename T>
class Ev {
public:
typedef result_of(T::toCPD()) D;
Run Code Online (Sandbox Code Playgroud)
实例化后Ev<A>,编译器说:
meta.h:12:错误:'T :: toCPD'不是一个类型
既不是类型也不是类型的工作.
我已阅读以下相关问题:
和cppreference.com 上的页面std::result_of.
所有这些似乎表明我应该能够使用:
std::result_of<int(int)>::type v1 = 10;
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用g ++ 4.9.2构建以下程序时
#include <type_traits>
int foo()
{
return 0;
}
int main()
{
std::result_of<int(int)>::type v1 = 10; // LINE A
std::result_of<decltype(foo)>::type v2 = 20; // LINE B
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到"LINE A"和"LINE B"的错误消息.错误消息是:
socc.cc: In function ‘int main()’:
socc.cc:10:5: error: ‘type’ is not a member of ‘std::result_of<int(int)>’
std::result_of<int(int)>::type v1 = 10;
^
socc.cc:11:5: error: ‘type’ is not a member of ‘std::result_of<int()>’
std::result_of<decltype(foo)>::type v2 = …Run Code Online (Sandbox Code Playgroud)