Destructor + inheritance causing program to crash after running?


I have a class which dynamically allocates memory for three data arrays, and as such in the destructor I told it to delete those data arrays.

However, when I've created a new class, and inherited the previous class - it will always crash AFTER running the program, unless I don't have the previous destructor present.

Is there any reason why this would happen?

Thank you.
In the base class constructor do you initialize the three pointers to NULL (aka 0 aka nullptr)? Or do you new[] them?

By doing either, you ensure that delete[]'ing them is a harmless operation.

Is your base class destructor marked as virtual?
Rule of thumb: a class that's meant to be inherited from should always have a virtual destructor, otherwise polymorphism won't work properly.

You could help us help you by posting your current source code. Then we wouldn't have to guess what the problem is.
Sorry I didn't reply earlier, I almost threw my laptop out.

But your solution did work, by setting the destructor as virtual, the code behaved as normal. Thank you.
I'll just leave this reply for the possible future, the one in which you get crashes again, but still do not throw out your laptop.

Implement a copy constructor and copy assignment operator for deep copying.
Topic archived. No new replies allowed.