I´m using a struct to support a list of Windows SOCKET´s:
struct ConnectedSockets{
std::mutex lock;
std::list<SOCKET> sockets;
};
When i try to compile this (Visual Studio 2012) i get the following error:
"Error C2248:
std::mutex::operator =
cannot access 'private' member declared in class'std::mutex'
"
Does anybody know how to fix this?
Root cause has nothing about sockets.
std::mutex
is not copyable, so compiler fails to generate default assignment operator (which is memberwise) forConnectedSockets
struct. You need to instruct compiler to delete assignment operator (declare it using= delete
specifier) or implement it manually, e.g. ignoring mutex copying.A
std::mutex
is not copyable, so you will need to implement theoperator=
forConnectedScokets
yourself.I presume you want to keep a
mutex
per instance ofConnectedSockets
, so this should be enough: