繁体   English   中英

C ++“错误:'class std :: result_of <…>中没有名为'type'的类型”

[英]C++ “error: no type named ‘type’ in ‘class std::result_of< … >”

我正在尝试编译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, 可通过Software Collections网站获得DTS

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM