I have a class called overlay_server which has a public method
void member_list_server(boost::asio::io_service &io_service){
Now I want to run this in a new thread. So I create a new thread, and use bind in its constructor.
Before I was creating an io_service inside the void member_list_server function. But Now I am trying create an io_service object in main and pass it to this thread where i get the error?
int main(){
boost::asio::io_service io_service_;
overlay_server overlay_server_(8002);
boost::thread thread_(
boost::bind(&overlay_server::member_list_server, overlay_server_, io_service_)
);
Why do I get the error
error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'
I will create instances of other classes also, which need io_service. What is the best way, should I create one io_service object in main and pass it to all threads?
or create a separate one inside all the threads I create in future?
io_servicemust outlive the thread, otherwise it will have a dangling reference. Soio_servicecan't be local as in your example. - Igor R.