I'm trying to use Boost's ASIO library to do easy networking on Windows for my project, but whenever I include anything that has to do with std::shared_ptr
and boost::asio::ip::tcp::acceptor
, I get this error:
'defer': is not a member of 'std::shared_ptr<boost::asio::io_context>'
bool ChatterboxService::Service::open()
{
context = std::make_shared<boost::asio::io_context>();
try
{
acceptor = std::make_shared<boost::asio::ip::tcp::acceptor>(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port));
}
catch (boost::system::system_error error)
{
std::cerr << error.what() << std::endl;
return false;
}
return true;
}
I've tried deleting, re-extracting, and re-compiling the entire library, but that made no difference. I've been Googling this problem for a couple of hours now and no-one else has ever seemed to have this problem. Any help at all is very much appreciated.
You are trying to construct acceptor from shared_ptr, you should dereference it.
try
{
acceptor = std::make_shared<boost::asio::ip::tcp::acceptor>(*context, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port));
}