3

I'm having this error when trying to instantiate a new object of a class. The code is:

using boost::asio::ip::tcp;
typedef boost::asio::io_service ioservice;

class cnx
{
public:
    cnx(ioservice io);

private:
    tcp::socket *s;
};

//constructor:
cnx::cnx(ioservice io)
{
    this->s = new tcp::socket(io);
}

outside the cpp/h file of cnx, I try to instantiate as:

ioservice io;
cnx c(io);

or

cnx* c = new cnx(io);

and both result in this error message. What can be causing this?

Fnr
  • 2,096
  • 7
  • 41
  • 76

1 Answers1

3

As @tkausl said in the comments and also thanks to this answer, the problem was because boost::asio::io_service is not copyable. Changing the definition of the constructor to:

cnx(ioservice& io);

and calling it through:

ioservice io;
cnx c(std::ref(io));

solved the problem

Fnr
  • 2,096
  • 7
  • 41
  • 76