Error with lib boost asio 1.47.0 in basic_socket.hpp file

I have an error in the following code when I tried to compile this:

void Server::accept(void) { Network::ptr connection = Network::initialize(this->my_acceptor.get_io_service()); this->my_acceptor.async_accept(connection->socket(), bind(&Server::endCmd, this, *connection, placeholders::error)); } void Server::endCmd(Network connection, const boost::system::error_code& error) { if (!error) { std::cout << "success!" << std::endl; connection.start(); this->accept(); } } 

VC ++ 2010 tell me the following error:

 Error 1 error C2248: 'boost::asio::basic_io_object<IoObjectService>::basic_io_object' : cannot access private member declared in class 'boost::asio::basic_io_object<IoObjectService>' 

I know that this error occurs on this line, because when I comment on it, the error disappears ... After some research, probably with the socket class, when I call connection->getSocket() , but this function returns ref in socket instance:

 tcp::socket& Network::socket(void) { return (this->my_socket); } 

so I did not find a solution on the Internet :(

Anyone have an idea plz?

+4
source share
2 answers

Is async_accept what you wrote? If so, make sure that it receives the LINK to the socket, not the value. The error you get indicates that you are trying to copy the construct, and the copy constructor is declared private (this is C ++ - a way to ensure that the class does not support copying).

+2
source

I also had this problem, and I spent several hours to find out what happened. My business was:

  • Class A containing an optional hopper. Class A was used as a member in class B.
  • class B was a pointer and it was not copied. Member A was declared as a reference in class B.

Source code in class B:

 std::bind(&A::a_member, a_instance) 

The problem has been fixed (and of course) using the address a_instance:

 std::bind(&A::a_member, &a_instance). 

I did not notice this, and I took the time to solve this problem. I hope this helps others too.

+2
source

Source: https://habr.com/ru/post/1380456/


All Articles