“No matching function for call to bind” while using websocketpp

杀马特。学长 韩版系。学妹 提交于 2019-12-12 02:16:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!