I want to make an abstract class in c++ with a single, but with some default implementation.
so that every class that inherits it will have default behavior but you cant create an instance of the base class.
but if i mark foo as pure virtual, I can’t 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 a pure virtual, and just hide the constructor.
I’m wondering if its possible to mark the class as pure, but still have some implementation?
You can add an implementation to a pure virtual function. Classes that derive can use the default implementation by explicitly invoking the base-class-method.