Inconsistent destructors...

Started by
2 comments, last by evanofsky 17 years, 11 months ago
So let's say I have a program like this:

class Object {
public:
   Object();
   ~Object();
   void foo();
};

Object::Object() {/** ... */}

Object::~Object() {
   PrintOutMessageToCommandPrompt();
}

int main() {
   Object object;
   object.foo();
}


This is basically what's happening in my current project. However, PrintOutMessageToCommandPrompt() is never called. If instead I do this:

int main() {
   Object* object = new Object();
   object->foo();
   delete object;
}


It calls PrintOutMessageToCommandPrompt(). I'm using VC++.net 2003. I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code. Thanks alot! [smile]
Advertisement
Quote:Original post by evanofsky
I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code.


Try printing something on the standard error stream (std::cerr) instead.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Quote:Original post by Fruny
Quote:Original post by evanofsky
I'm pretty sure it has nothing to do with any of the code implementation details; I'm just calling ::MessageBox() in the actual code.


Try printing something on the standard error stream (std::cerr) instead.
In other words, the object is destructed at a point at which it is no longer valid to display a messagebox since your app is mostly destroyed.

A breakpoint in the destructor should confirm that the code is still being reached.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Okay, that makes sense. It reaches the breakpoint now. The reason I asked this question is because PIX told me that none of my textures had been deleted. Of course, I never explicitly delete them, because I'm using an ID3DXEf- nevermind, this is a question for the DirectX forum. [wink]

Thanks alot for the help!

This topic is closed to new replies.

Advertisement