mercredi 30 mars 2016

MultiThreading C++ MacOSX error: using deleted function

So sorry for any errors in formatting. I had a difficult time trying to paste the code.

I'm trying to do multithreading and I'm having these errors from Xcode. The ServerSocket uses socket.h. And I used thread.h from C++11 for this. The file the error message refers to is #include

void start_thread(ServerSocket& sock){
try{
    string data; string command;
    while(true){
        sock >> data;
        cout << "Client reply: " << data << endl;
        cout << ">" ;
        getline(cin, datasend);
        sock << datasend;
    }
    }catch(SocketException&){}
}



void start(){
    try {
        ServerSocket server (PORT); 
        while (true){
            Client new_cli(++cli_id);
            server.accept(new_cli.socket());
            thread start_thread(start_thread,new_cli.socket());
        }
    }catch (SocketException& e){
        cout << "Socket Exception: " << e.description() << endl;
    }
}
int main(){start()}

g++ ServerSocket.cpp Client.cpp server.cpp -std=c++14 -pthread In file included from server.cpp:4: /Applications/http://ift.tt/1PGGPRK: error: attempt to use a deleted function __invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...); ^ /Applications/http://ift.tt/1MCHFEE: note: in instantiation of function template specialization 'std::__1::__thread_execute' requested here __thread_execute(*__p, _Index()); ^ /Applications/http://ift.tt/1PGGPRM: note: in instantiation of function template specialization 'std::__1::__thread_proxy >' requested here int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get()); ^ server.cpp:55:11: note: in instantiation of function template specialization 'std::__1::thread::thread' requested here start_thread(start_thread,new_cli.socket()); ^ /Applications/http://ift.tt/1MCHFEG: note: '~__nat' has been explicitly marked deleted here ~__nat() = delete; ^ 1 error generated.

Aucun commentaire:

Enregistrer un commentaire