简体   繁体   中英

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

I am trying to compile a gRPC server, but I get the error:

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...>)

My guess is this line in wavenet_server.cc :

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

is introducing ambiguity ( the compiler does not know if this is a function decloration or an expression, maybe? )

So I tried to replace the line with:

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

but that did not work either

Is this the correct source of the problem? and how may I fix it? If that line is not the problem, then please let me know ( The source code is too long to paste, and I cannot tell which line is the problem because I cannot understand the error message, but I will try my best ).

You need a newer GCC version if you want to use C++11 features such as std::result_of . GCC 4.8 has only very experimental C++11 support. It is generally recommended to use it only in C++98 mode.

If you want to use C++11 on Red Hat Enterprise Linux 7, you should get a recent version of Red Hat Developer Toolset:

For CentOS, DTS is available through the Software Collections site .

Please keep in mind that due to the way DTS works, you need to compile all C++11 code with DTS, so you cannot use a precompiled gRPC library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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