|
Re: Order of Object destruction: msg#00207gcc.help
Eljay Love-Jensen wrote: Hi Neophytos, The example that you show I understand and it's fine. But the two objects I was refering two was not "a" and "b" as you have above, but "b" and the temprary object created by the copy constructor once function foo is entered. Look at the code again: A foo(A z) { cout << "In foo Object #: " << z.y << endl; return z; } int main() { A a; cout << foo(a).y << endl; return 0; } When the call foo(a) is made the copy constructor is called and makes a new object "z". This object "z" is supposed to be desposed off when it goes out of scope. When the return happens in foo, the copy constructor is called again and given "z" as an argument (a reference to "z") it creates a new object (let's call it "b" as you did above). When "b" gets created there is no reference to "z" anymore (and that's why I don't understand your example above). I was asking which was supposed to be desposed of first "z" or "b"? Visual C++ disposes "z" first and then "b". g++ does the opposite. Does the standard say which has to go first? If it does then one of the two compilers is in error. Thanks, Neophytos |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Order of Object destruction: 00207, Eljay Love-Jensen |
|---|---|
| Next by Date: | Re: Order of Object destruction: 00207, Eljay Love-Jensen |
| Previous by Thread: | Re: Order of Object destructioni: 00207, Eljay Love-Jensen |
| Next by Thread: | Re: Order of Object destruction: 00207, Eljay Love-Jensen |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |