object of abstract class type “Connection” is not allowed

前端 未结 3 898
终归单人心
终归单人心 2021-01-21 03:59
class Connection
{
public:
  typedef boost::shared_ptr pointer;
  static pointer create(boost::asio::io_service& io_service){return pointer(new Con         


        
3条回答
  •  没有蜡笔的小新
    2021-01-21 04:28

    You have not provided a definition for OnReceived, it is therefore a pure virtual (abstract) method and the class an abstract class. You cannot instantiate an object of an abstract class. To use the method OnReceived you have to, well, provide an implementation for it (what does it do at the moment? nothing). Abstract classes are intended to be subclassed by concrete implementations which then provide implementations for the pure virtual methods.

    EDIT: The part new Connection(io_service) does not work for the above mentioned reason: you cannot create an object of a class, that has pure virtual functions (those declarations ending with = 0;). You need to subclass Connection and provide implementations for those methods (like OnConnected). Your old class didn't have that problem. It had pure virtual methods, but you have not tried to instantiate it. If you still don't see the error, I suggest you to consult some material on object-orientation in C++, especially virtual and pure virtual methods.

提交回复
热议问题