Search code examples
c++boostboost-asioasio

Implicit instantiation of undefined template 'boost::enable_shared_from_this<TCP_Connection>'


I've been trying to follow a Boost tutorial to integrate Asio for a few hours now, but I have a class inheritance problem with Boost's enable_shared_from_this class. I've included everything I needed for this class but the problem still persists and I'm not sure what this message means

Implicit instantiation of undefined template 'boost::enable_shared_from_this<TCP_Connection>'

#pragma once

#include <boost/asio.hpp>
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <array>

using boost::asio::ip::tcp;

class TCP_Connection : public boost::enable_shared_from_this<TCP_Connection> {
public:
    typedef boost::shared_ptr<TCP_Connection> pointer;

    static pointer create(boost::asio::io_context &ioc);
    tcp::socket& socket();
    void start();
private:
    explicit TCP_Connection(boost::asio::io_context &ioc);
    void handleWrite();

    tcp::socket _socket;
    std::string _message;
};

Solution

  • #include <boost/enable_shared_from_this.hpp>