使用g ++的C ++ 11中关于互斥锁的编译错误是什么?

Ufo*_*rob -3 c++ mutex g++ c++11

这是什么c ++编译错误?我已经在另一台已配置的机器上编译了我的代码,所以我想我错过了在环境中要在C ++ 11中编译的东西(代码使用--std = c ++ 0x选项进行编译)。该错误似乎与C ++ 11中的新互斥功能有关。

In file included from /usr/include/c++/4.6/mutex:43:0,
                 from include/Ric_box_tele.h:4,
                 from src/Ric_box_tele.cpp:1:
/usr/include/c++/4.6/functional: In member function ‘void std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__call(std::tuple<_Args ...>&&, std::_Index_tuple<_Indexes ...>, typename std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__enable_if_void<_Res>::type) [with _Res = void, _Args = {}, int ..._Indexes = {0, 1, 2}, _Result = void, _Functor = std::_Mem_fn<void (Ric_box_tele::*)(Socket, int)>, _Bound_args = {Ric_box_tele*, Socket, int}, typename std::_Bind_result<_Result, _Functor(_Bound_args ...)>::__enable_if_void<_Res>::type = int]’:
/usr/include/c++/4.6/functional:1378:24:   instantiated from ‘std::_Bind_result<_Result, _Functor(_Bound_args ...)>::result_type std::_Bind_result<_Result, _Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {}, _Result = void, _Functor = std::_Mem_fn<void (Ric_box_tele::*)(Socket, int)>, _Bound_args = {Ric_box_tele*, Socket, int}, std::_Bind_result<_Result, _Functor(_Bound_args ...)>::result_type = void]’
/usr/include/c++/4.6/thread:117:13:   instantiated from ‘void std::thread::_Impl<_Callable>::_M_run() [with _Callable = std::_Bind_result<void, std::_Mem_fn<void (Ric_box_tele::*)(Socket, int)>(Ric_box_tele*, Socket, int)>]’
src/Ric_box_tele.cpp:453:1:   instantiated from here
/usr/include/c++/4.6/functional:1287:4: error: use of deleted function ‘Socket::Socket(const Socket&)’
include/Socket.h:43:5: error: declared here
/usr/include/c++/4.6/functional:550:7: error:   initializing argument 2 of ‘_Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class*, _ArgTypes ...) const [with _Res = void, _Class = Ric_box_tele, _ArgTypes = {Socket, int}]’
Run Code Online (Sandbox Code Playgroud)

Yak*_*ont 5

您有一个方法按值Ric_box_tele接受Socket变量(签名似乎是void method(Socket, int)-我不知道函数的名称是什么,因为您没有包括生成错误的代码行)。

Socket 变量不能被复制(其复制构造函数被删除)。

该错误与文件453行中的内容有关src/Ric_box_tele.cpp,您没有将其包括在问题中。在该行上,您正在创建一个std::thread,可能会向其传递一个套接字,也许还有上述方法和指向该对象的指针。

Bind错误可能来自std::thread采用n元成员函数指针并将其自动转换为n + 1元可调用对象的能力,并且该实现是在实现细节中实现的(可能是std::bind等效的内部机制)。它只会给核心错误消息增加噪音。

通常,在解码C ++库错误时,您要查看提到自己的代码的哪一行,然后要查看最内层的错误。

最里面的错误是use of deleted function ‘Socket::Socket(const Socket&)’,您自己的代码所在的行是“文件的453行src/Ric_box_tele.cpp”。其他所有内容对于查看两者如何相互连接也很有用。