Consider the following two code snippets, The first one:
#include "pch.h"
#include <memory>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
class tcp_connection : public std::enable_shared_from_this<tcp_connection>
{
public:
typedef std::shared_ptr<tcp_connection> pointer;
static pointer create(boost::asio::io_service& io_service)
{
return pointer(new tcp_connection(io_service));
//second example only differs by replacing the above line with the below one
//return std::make_shared<tcp_connection>(io_service);
}
private:
tcp_connection(boost::asio::io_service& io_service) //private constructor
: socket_(io_service)
{
}
tcp::socket socket_;
};
int main()
{
return 0;
}
The second one only differs from the first with one line, that is, the commented line.
With MSVC 2017 and boost::asio 1.68, the first version works as intended, while the second one doesn't compile, spitting out errors such as "incomplete type is not allowed tcp_async".
My question is:
- Is this because std::make_shared doesn't play along with std:std::enable_shared_from_this?
- Or, it is because assumptions that asio holds about how std::make_shared or std::enable_shared_from_this are implemented, doesn't hold with MSVC 2017.
- Or it's something else?