Possible Duplicate:
Destructors for C++ Interface-like classes
Consider a simple example of a C++ abstract class, used to model an interface:
class IAnimal
{
virtual void walk()=0;
virtual ~IAnimal(){}
};
Is it better to have the destructor, or not? I don’t think the destructor can be pure virtual, at least my tests give linker errors, so should an empty destructor be included?
EDIT: sorry, typo. It’s a destructor not a constructor.
You should always use a virtual destructor with interfaces. Case in point:
Now what destructor is it going to use? Definately not the Lion’s destructor because the interface doesn’t know about Lion’s destructor.
So, have this if your interface has no memory management: