I think you need to write ~Derive() like this
~Derived() { delete some; some = 0; //this is must; so that `delete some` in ~Base() works perfectly; //note `delete (void*)0` is fine in C++! }
Explanation:
Why would you write this even if ~Base() does the same (it looks like it does the same) because ~Derived() ensures that you remove your object from the same heap / memory -pool / etc they were created.
See these topics:
How to use a class in a DLL? Memory Management with char * Return Function
EDIT:
It would be better to add another virtual function, say deinit() , (the back of your virtual void init() ), override this also when overriding init() and do the division in deinit() .
//DLL class Base { protected: Something *some; public: virtual void init() { some = new Something(); } virtual void deinit() { delete some; } virtual ~Base() { deinit(); } }; //EXE class Derived : public Base { public: virtual void init() { some = new SomethingElse(); } virtual void deinit() { delete some; //some=0 is not needed anymore! } };
source share