Is this safe ?
class Derived: public PublicBase, private PrivateBase
{
...
~Derived()
{
FunctionCall();
}
virtual void FunctionCall()
{
PrivateBase::FunctionCall();
}
}
class PublicBase
{
virtual ~PublicBase(){};
virtual void FunctionCall() = 0;
}
class PrivateBase
{
virtual ~PrivateBase(){};
virtual void FunctionCall()
{
....
}
}
PublicBase* ptrBase = new Derived();
delete ptrBase;
This code crases sometimes with IP in a bad address.
That is not a good idea to call a virtual function on constructor is clear for everyone.
From articles like http://www.artima.com/cppsource/nevercall.html I understand that destructor is also a not so good place to call a virtual function.
My question is "Is this true ?" I have tested with VS2010 and VS2005 and PrivateBase::FunctionCall is called. Is undefined behavior ?