C++ "error: no type named ‘type’ 在 ‘class std::result_of< ... >"

标签 c++ c++11 g++ grpc

我正在尝试编译 gRPC 服务器,但出现错误:

In file included from /usr/include/c++/4.8.2/mutex:42:0,
                 from /usr/include/c++/4.8.2/condition_variable:39,
                 from /home/msl/maum/include/grpc++/server.h:22,
                 from wavenet_server.cc:2:
/usr/include/c++/4.8.2/functional: In instantiation of ‘struct std::_Bind_simple<std::_Mem_fn<void* (WavenetServiceImpl::*)(void*)>(void**)>’:
/usr/include/c++/4.8.2/thread:137:47:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void* (WavenetServiceImpl::*)(void*); _Args = {void* (&)[2]}]’
wavenet_server.cc:317:73:   required from here
/usr/include/c++/4.8.2/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void* (WavenetServiceImpl::*)(void*)>(void**)>’
       typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                             ^
/usr/include/c++/4.8.2/functional:1727:9: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void* (WavenetServiceImpl::*)(void*)>(void**)>’
         _M_invoke(_Index_tuple<_Indices...>)

我猜是 wavenet_server.cc 中的这一行:

std::thread t(&WavenetServiceImpl::threadWavenetInfer, thread_args);

正在引入歧义(编译器不知道这是函数声明还是表达式,也许吧?)

所以我尝试将这一行替换为:

std::thread t{&WavenetServiceImpl::threadWavenetInfer, thread_args};

但是还是不行

这是问题的正确根源吗?我该如何解决?如果不是那一行的问题,请告诉我(源代码太长,无法粘贴,我无法判断是哪一行的问题,因为我无法理解错误信息,但我会尽力而为)。

最佳答案

如果您想使用 C++11 功能,例如 std::result_of,您需要更新的 GCC 版本。 GCC 4.8 只有非常实验性的 C++11 支持。一般建议只在C++98模式下使用。

如果您想在 Red Hat Enterprise Linux 7 上使用 C++11,您应该获得最新版本的 Red Hat Developer Toolset:

对于 CentOS,DTS is available through the Software Collections site .

请记住,由于 DTS 的工作方式,您需要使用 DTS 编译所有 C++11 代码,因此您不能使用预编译的 gRPC 库。

关于C++ "error: no type named ‘type’ 在 ‘class std::result_of< ... >",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52645571/

相关文章:

c++ - Box2D 如何停止播放器(盒子)旋转

c++ - std::vector<bool> 保证默认所有条目为假?

c++ - 是否有任何编译器支持 constexpr?

c++ - 获取 Windows 消息名称

c++ - 指向指针数组的指针

c++ - 无法在 Switch Case 中调用函数 - C++

c++ - 如何使用 make_heap 在 C++ 中创建最小堆

c++ - gcov 函数未执行,但行已执行

c++ - 在cpp中对象初始化后设置数组的边界

c++ - 无法将 LIBEVENT 链接为 C++