相关疑难解决方法(0)

decltype,result_of或typeof?

我有:

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'不是一个类型

既不是类型也不是类型的工作.

c++ type-inference c++11

12
推荐指数
1
解决办法
2万
查看次数

为什么std :: result_of <int(int)> :: type有效?

我已阅读以下相关问题:

  1. std :: result_of简单函数
  2. decltype,result_of或typeof?

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)

c++ c++11

8
推荐指数
2
解决办法
1274
查看次数

标签 统计

c++ ×2

c++11 ×2

type-inference ×1