I get the following errors
Error 2 error C2248: ‘std::thread::thread’ : cannot access private
member declared in class
‘std::thread’ c:\dropbox\prog\c++\ttest\ttest\main.cpp 11 1 ttestError 1 error C2248: ‘std::mutex::mutex’ : cannot access private
member declared in class
‘std::mutex’ c:\dropbox\prog\c++\ttest\ttest\main.cpp 11 1 ttest
my code
#include <mutex>
#include <thread>
using namespace std;
struct Serverbas
{
mutex mut;
thread t;
};
struct LoginServer : Serverbas
{
void start()
{
t = thread(&LoginServer::run, *this);
}
void run() {}
};
int main() {}
That first argument to the member function
run(implicit in direct calls) should be thethispointer, i.e. justthis. Don’t dereference it.When you dereference it all hell breaks loose because your
std::threadandstd::mutexmembers prevent objects of your class type from being copyable — the copy constructors of these member objects areprivate/deleted and that is the error you are seeing.So: