I have an abstract base class with one purely virtual method:
class Base
{
public:
virtual void update() = 0;
};
Is there any way I could create a class that inherits from Base
, overrides the update
method, but still forces its children to implement an update
method? Like this:
class Base2 : public Base
{
public:
void update() override
{
if(bSomeCondition)
{
update(); //Calls child's update method
}
}
virtual void update() = 0; // Obviously not like this
};
I know I could create two new purely virtual methods with slightly different names in Base2
, and just override those in child classes, but I would really like to keep these method names if that would be possible.
I'm guessing this isn't possible?
Base
, not fromBase2
. In other words, don't derive from concrete (instantiable) classes. C++11 and later, that can be enforced by taggingBase2
asfinal
. – Peter// Obviously not like this
" -- well, obviously the line stating "obviously" is the obvious way to do it. It's the inline definition above the "obviously" line that is obviously the problem. :) Have I mentioned recently that "obviously" more often qualifies false statements than true ones? Always doubt yourself whenever you find yourself saying something is obvious! – JaMiT