Boost logo

Boost Users :

Subject: [Boost-users] Passing io_service to socket in implementation file after initialization in header file
From: Álvaro Cebrián Juan (acebrianjuan_at_[hidden])
Date: 2018-06-18 13:12:54


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 <boost/asio.hpp>
>
> 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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net