ORDER IN WHICH OBJECTS ARE DESTROYED
| G SATISH KUMAR (16) | |||
| class a{--------- ---------}; int main(){ {a q,w,e; } } doubt:in the above program object 'q' is created first then 'w' and later 'e' is created. when cursor moves out of block in main in which 3 objects are created,destructor is called automatically and destroys objects in the reverse order in which they are created.that is 'e' is destroyed first then 'w' is destroyed and then 'q' is destroyed. but how can we confirm that objects are destroyed in the reverse order in in which they are created?????? please write a program to confirm the above discussion. | |||
| jsmith (958) | |||
| Hint: Give each instance of the object (via constructor) a unique name, and output that name in the destructor for the object. | |||
| rpgfan3233 (111) | |||
Yeah something like this should work:
| |||
This topic is archived - New replies not allowed.
