object of abstract class type “Connection” is not allowed

前端 未结 3 869
终归单人心
终归单人心 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:25

    You have decided to make Connection abstract, but then attempted to instantiate it. Which did you mean to do?

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-21 04:34

    You an use it, but not until it is implemented in some derived class.

    You cannot create objects of abstract classes, because not all functions are implemented.

    0 讨论(0)
提交回复
热议问题