Sign in to follow this  
evanofsky

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this