cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Why are destructors called in reverse?
Page 2
Why are destructors called in reverse?
Pages:
1
2
May 16, 2013 at 12:02pm UTC
keskiverto
(10402)
1. Is there order for t1 and t2?
2.
Anmol444
wrote:
A's constructor
T's constructor
T's constructor
Look again at:
1
2
3
4
A::A() : t2( 42 ) { t1 = 7; }
You say that lines 2-4 (the A's constructor) are executed before either t1 or t2 has been constructed. If so, you could not use t1 on line 3 ...
May 16, 2013 at 1:28pm UTC
LB
(13399)
Confusion resolution: use the order the constructors end, not the order the constructors start.
May 16, 2013 at 8:55pm UTC
Anmol444
(638)
Oh yea T's constructor must have been called, before, otherwise it wouldn't work.
@LB
Why?
May 16, 2013 at 9:44pm UTC
LB
(13399)
Because A's constructor does start before T's, but T's ends before A's
May 16, 2013 at 10:14pm UTC
Anmol444
(638)
But he said Ts start before. But yea T's ends before A's. But how is this supposed to help me?
Im so clueless...
May 16, 2013 at 10:25pm UTC
LB
(13399)
A's ctor
starts
before T's because as soon as it starts it calls T's ctor.
May 17, 2013 at 12:17am UTC
Anmol444
(638)
Ooo ok, I thought it was the opposite cause technically it didnt start cause no statements from it were really executed. Alright thanks guys, I got it I shall use the first person's reply and cire's reply as the reason. Thanks!
Topic archived. No new replies allowed.
Pages:
1
2