C++ Forcing Method Override In Concrete Class

后端 未结 5 2453

Is there a way in C++ to write a concrete class which when another class is derived from it, has a method which must be overriden. An abstract class allows the forcing of the de

5条回答
  •  礼貌的吻别
    2021-02-20 06:43

    No, it is not possible. If you want to enforce (in compile time) a derived class to define a virtual function then its base class needs to be abstract, or in other words the base class needs to have a pure virtual function. Abstract class (with pure virtual function(s)) cannot be concrete, i.e. you cannot instantiate it.

提交回复
热议问题