# Inconsistent destructors...

## Recommended Posts

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]

##### Share on other sites
Quote:
 Original post by evanofskyI'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.

##### Share on other sites
Quote:
Original post by Fruny
Quote:
 Original post by evanofskyI'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.

##### Share on other sites
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!