destructor not called?

This is a discussion on destructor not called? within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I have a question about destructors. I've written a simple class, to simulate a fertiliser tanker using a ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    7

    destructor not called?

    Hi everyone,

    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:

    Code:
     
    
    ~Tanker();
    in the implementation file the code is:

    Code:
    Tanker::~Tanker()
    {
    	cout << "Tanker object destroyed" << endl;
    }
    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.

    I'm not sure if I'm missing something here? Like I say, everything else is working fine.

    Thanks for your help,

    Justin

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Quote Originally Posted by waysgoose View Post
    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.
    is your object local for the main or global?

    show the minimal compilable sample illustrating the problem
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Looks fine, and it works here on MinGW.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    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.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alphabetically sorting argv[]
    By serg_yegi in forum C Programming
    Replies: 7
    Last Post: 03-27-2010, 07:25 PM
  2. Is DllMain's DLL_PROCESS_DETACH called when process is killed?
    By chiefmonkey in forum Windows Programming
    Replies: 3
    Last Post: 10-09-2009, 02:03 AM
  3. Destructor being called on SGI hash_map key
    By cunnus88 in forum C++ Programming
    Replies: 4
    Last Post: 02-10-2009, 11:05 PM
  4. Replies: 4
    Last Post: 09-21-2008, 02:27 PM
  5. callback from exe called with system()
    By leonv in forum C Programming
    Replies: 3
    Last Post: 01-25-2008, 03:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21