“No matching function for call to bind” while usin

2019-08-16 13:59发布

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?

2条回答
Summer. ? 凉城
2楼-- · 2019-08-16 14:38

Take a look at the boost documentation. There is a good example.
You need to resolve the ambiguity by your self.

查看更多
爷的心禁止访问
3楼-- · 2019-08-16 14:51

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()

查看更多
登录 后发表回答