![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Can you call a constructor within a destructor, or vise vesa?folks, I came across questions about calling constructor or destructor.
I am curious whether you can: Code:
So I wrote the following code and want to share with you what I got. Comments are welcomed! Please check if I miss anything. 1. call a constructor in a constructor Code:
Basically you are not actually calling the constructor, you are just generating a temp object. If you use this->A() to call then you will get an error. Code:
Also this brings a recursive calling. Soon you will use up memory and crash. 2. call a destructor in a constructor Code:
You can't call ~A() without qualifying: this->~A(). At least I didn't figure out a way to avoid it. Yes, you can call destructor in the class, and you can see it destructs the member variable x. 3. call a constructor in a destructor Code:
4. call a destructor in a destructor Code:
This also gives you a dead loop. 5. call a constructor in a member function Code:
It works. just a temp obj. 6. call a destructor in a member function Code:
It works. |
|||
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two bugs in my program that just won't go away. | randomperson133 | Assembly Language | 1 | 23-Mar-2008 08:04 |
| Will pay through Paypal if somebody helps me. | paritoshcool | Assembly Language | 0 | 27-Nov-2007 23:27 |
| Fortran problem... | Justin Fox | Miscellaneous Programming Forum | 6 | 24-Oct-2006 16:30 |
| how to get Call graph for applications, anybody knows | bravetanveer | C Programming Language | 1 | 30-Sep-2005 00:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The