Printing the Object Killed by the Decontructor

Can I print to the console the address of the object that is being destroyed in the Deconstructor?
for example how would I do this basic thing.

1
2
3
4
5
CTest::~CTest(){ 
	 
        cout << "Deleted Object " << this << endl; 
                    
        };


Thanks for any help.
Eric
Last edited on
Yes you can.
How can you tell what type of Object it is?

Does "this" know that the actual instance is? and if so can I print

1
2
3
4
5
6
int main(){

      CTest MyObject;

Return 0;
}

At this point I want to print "MyObject" has been Deconstructed.

Is this possible for an object to know this?

In your example, within the destructor (it's not "deconstructor" by the way) of CTest, the type of this is CTest*, and it points at MyObject (that is, it holds the address of the first byte on main()'s stack frame that's occupied by that object).
I am really new to C++ so forgive my noobness. :)

I just want to cout << ????? << endl;

????? = the Text "MyObject"

Can I make this happen in my deconstructor?
Topic archived. No new replies allowed.