Actually, I have no idea, why. You can do the following as well:
class IDemo
{
public:
virtual ~IDemo() {}
virtual void OverrideMe() = 0;
};
class Child : public IDemo
{
public:
virtual void OverrideMe()
{
//do stuff
}
~Child()
{
}
};
Everything depends only on your program's architecture and what actually Parent
and Child
are. Look at the C# example - IDisposable
is an interface, which allows one to dispose resources used by the class, which implements it. There is no point in requiring a base class - it would even make using IDisposable
harder to use, because maybe I don't want the base class functionalities (despite fact, that every .NET class derives from Object
, but that's another story).
If you provide more information about your actual program's architecture, we may be able to judge, whether a base class is needed or not.
There's another thing worth pointing out. Remember, that in C++ IDemo actually is a class, it's an interface only from your point of view. So in my example, Child actually has a base class.