here come the pitfall, consider this
struct IBase
{
virtual void doSomething() = 0;
}
class Derived : public IBase
{
Derived() { text = new char[64]; }
virtual ~Derived() { delete [] text; }
virtual void doSomething() { printf("%s", text);
}
IBase *obj = new Derived();
delete obj;
It was looking perfectly fine to me, until i placed a break point in the derived class destructor. one of the solution is to add a virtual destructor to IBase, but this is ugly and unbalance. the solution I adopted was use self made init() and uninit() insteads.
No comments:
Post a Comment