destructor not called?
I have a question about destructors. I've written a simple class, to simulate a fertiliser tanker using a header file and an implementation file. Then I've used a file with a main method to test it.
Everything is working fine, except for the destructor I have written. I've included a cout statement, so that it is possible to tell that the destructor has been called, but the output is not being showed. I'm compiling everything in DevC++, but running it from the command line.
My code for the destructor in the header file is:
in the implementation file the code is:
I've written destructors before, and they have worked. They were single file programs, with main method, class declarations and implementation all in the same file.
cout << "Tanker object destroyed" << endl;
I'm not sure if I'm missing something here? Like I say, everything else is working fine.
Thanks for your help,
is your object local for the main or global?
Originally Posted by waysgoose
show the minimal compilable sample illustrating the problem
Looks fine, and it works here on MinGW.
The problem is not with your destructor, the problem is with the rest of your program. You might for example be allocating a Tanker via new, and not deleting it.
Please show all the relevant code that uses Tanker.