问题
I'm making an (c++) application which is a websocket client and websocket server. To be able to do this, I'm using the library websocketpp. To make the application both a client and server, I want the endpoint1.run()
and endpoint2.listen(port)
to be multi-threaded. This is where something goes wrong.
Normally (single thread) I use: endpoint.listen(port);
which works.
To make it into a multi-thread I use:
boost::thread t(boost::bind(&server::listen, &endpoint, port));
sleep(1);
cout << "After thread! \n";
t.join();
However, I get the error:
main.cpp:116: error: no matching function for call to ‘bind(<unresolved overloaded function type>, websocketpp::server*, uint16_t&)’
server::listen
is an overloaded function, should I call it differently in bind?
回答1:
Take a look at the boost documentation. There is a good example.
You need to resolve the ambiguity by your self.
回答2:
For those who are still wondering how to implement this:
void(websocketpp::role::server<websocketpp::server>::*f)(uint16_t,size_t) = &websocketpp::role::server<websocketpp::server>::listen;
boost::thread t(f, &endpoint, port, 1); //No need to use boost::bind here
and after that call t.detach() or endpoint.stop() and t.join()
来源:https://stackoverflow.com/questions/10734236/no-matching-function-for-call-to-bind-while-using-websocketpp