pure virtual function and abstract class

前端 未结 2 367
挽巷
挽巷 2021-01-25 07:58

I have the following classes, Base and Derived and when I compile the compiler complains that it cannot create an instance of DLog because it is abstract.

Can someone te

2条回答
  •  悲&欢浪女
    2021-01-25 08:39

    By deriving your DLog class from Logger you are assuring that you will provide the implementation for all (assuming you don't want DLog as an abstract class) pure virtual methods declared in the base class. Here you have not provided implementation to pure virtual functions hence class DLog becomes an abstract class. In C++ you can not create an instance of an abstract class hence you get the compiler error. BTW, your base class is missing the virtual destructor.

提交回复
热议问题