Thread: Destructor causes compiler error with hard exit?

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    18

    Destructor causes compiler error with hard exit?

    If I hard exit the debug version of my exe, I get a compiling error from class destructors that havn't been called yet. Does this mean I have built the destructors wrong, or is it normal because the program quit before the destructor would have been called under normal conditions?

    Code:
    class Class
    {
    private:
    int x;
    int y;
    
    public:
    Class()
    {
     x = 0;
     y = 0;
    }
    ~Class(){}
    
    };
    That's the basic form of my classes.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Any error that occurs after your program starts is a run-time error, not a compile-time error.
    You haven't described what you mean by "hard exit".
    There is nothing in such a simple mocked up code snippet that tells us anything remotely useful.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    18
    Quote Originally Posted by iMalc View Post
    Any error that occurs after your program starts is a run-time error, not a compile-time error.
    You haven't described what you mean by "hard exit".
    There is nothing in such a simple mocked up code snippet that tells us anything remotely useful.
    If I close the debug version of my .exe by literally closing(x) the window. My compiler says there was an access violation. This only happens if there are destructors that would have been called had the program ended on its own terms.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Post the smallest and simplest compilable program that demonstrates the problem.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I would not call that a hard exit. I would call that simply closing the app.

    If I was going to use the term "hard exit", I would use it to mean directly "terminating the process".
    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. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM
  3. Replies: 2
    Last Post: 07-06-2005, 07:11 PM
  4. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 09:48 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM