Virtual methods can be potentially dangerous (or in best case cause strange behaviour) if you call them during the destruction of an inherited object.
Let's say you have the following classes:
class foo {
public:
foo();
~foo() { Cleanup() };
virtual void Cleanup();
}
class bar : public foo {
public:
bar()
:foo() {};
~bar();
virtual void Cleanup()
{
foo::Cleanup();
// Do some special bar() related cleanup now...
}
}
Let's say you create an object of type bar(), which is actually a foo() based on the inheritance hierarchy. When you delete the bar() object, the bar() destructor gets invoked first, followed by the foo() destructor. In an attempt to minimise calls to the Cleanup() routine, the call to this has been put in the foo() destructor. However, when this is called, the bar() object has already been destroyed, which means foo::Cleanup() won't exist in the vtable, and it will call the bar::Cleanup() method instead.
This could result in strange behaviour, like memory leaks, or inconsistent system state which could be a ticking time bomb waiting to cause problems further down the line.
I have been bitten by this sort of strange behaviour in the past, so it's certainly something to look out for.