Boost logo

Boost Users :

Subject: Re: [Boost-users] new user got compile error
From: Kenny Riddile (kfriddile_at_[hidden])
Date: 2008-12-01 17:37:53


boost001 wrote:
>
>
> Steven Watanabe-4 wrote:
>> AMDG
>>
>> James Peng wrote:
>>> class Server{
>>>
>>> public:
>>> Server(){};
>>> ~Server(){};
>>>
>>> void print();
>>> protected:
>>>
>>> private:
>>>
>>> boost::asio::io_service io_service;
>>> boost::asio::ip::tcp::acceptor acceptor(io_service,
>>> boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13));
>>> boost::asio::ip::tcp::socket asio_socket(io_service);
>>> boost::system::error_code error_read;
>>>
>>> };
>> You can't initialize members in the class body.
>>
>> In Christ,
>> Steven Watanabe
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>
> I think I did this with ACE and other library. Boost is special? So I should
> use pointer?
>

No, Boost isn't special. C++ doesn't allow you to initialize members in
the class body. You need to use the constructor's initialization list
like so:

Server::Server()
   : acceptor( io_service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 13) )
   , asio_socket( io_service )
{

}


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