Move your initialization of sock into the initialization list. Eg: foo::foo() : sock{ios} {}. Without this, the socket is default constructed without any io service and then you tried to invoke the call operator, not the constructor. On Mon, Jun 18, 2018, 09:13 Álvaro Cebrián Juan via Boost-users < boost-users@lists.boost.org> wrote:
If I initialize an io_service object and a socket object in my header file, how do I pass io_service to the socket as a parameter in my implementation file?
Take this header file as an example:
// foo.h
#include
class foo { public:
foo(); // Constructor.
private:
boost::asio::io_service ios;
boost::asio::ip::udp::socket sock; };
And the corresponding implementation file:
// foo.cc
#include "foo.h"
foo::foo() { sock(ios); // <-- This throws a compiler error. }
Why doing *sock(ios);* doesn't work? What is the proper way to do it?
Thank you.
Álvaro _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users