Boost logo

Boost Users :

Subject: Re: [Boost-users] Passing io_service to socket in implementation file after initialization in header file
From: William Jagels (william_at_[hidden])
Date: 2018-06-18 13:35:36


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_at_[hidden]> 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 <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 mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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