C ++ abstract class with some implementation

I want to create an abstract class in C ++ with one, but with some default implementation. so that every class that inherits it will have default behavior, but you cannot create an instance of the base class. but if I mark foo as pure virtual, I cannot add an implementation to it.

class Base { public: virtual void foo() =0; //Now I can't add foo implementation }; 

My solution was to not have it as pure virtual, and just hide the constructor. I am wondering if it is possible to mark the class as clean, but still have some implementation?

+4
source share
1 answer

You can add an implementation to a pure virtual function . Classes that receive can use the default implementation by explicitly calling the base class method.

+9
source

Source: https://habr.com/ru/post/1390182/


All Articles