Reputation: 3
Class "a" contains attributes: service_ of type boost::asio_ioservice and sock_, a unique_ptr of type boost::asio::ip::tcp::socket.
The following constructor code exists with sock_ properly pointing at a new socket object.
a::a() : service_(), sock_(new boost::asio::ip::tcp::socket(service_))
{
}
The following constructor code does not. The debugger lists sock_ as "empty".
a::a() : service_(), sock_(nullptr)
{
sock_(new boost::asio::ip::tcp::socket(service_));
}
Why?
Upvotes: 0
Views: 165
Reputation: 393759
As a statement:
sock_(new boost::asio::ip::tcp::socket(service_));
is simply not valid c++. Did you think of
sock_.reset(new boost::asio::ip::tcp::socket(service_));
instead?
Or
sock_ = std::make_unique<boost::asio::ip::tcp::socket>(service_);
Upvotes: 2