Why are destructors called in reverse?

Pages: 12
May 16, 2013 at 12:02pm
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
Confusion resolution: use the order the constructors end, not the order the constructors start.
May 16, 2013 at 8:55pm
Oh yea T's constructor must have been called, before, otherwise it wouldn't work.


@LB

Why?
May 16, 2013 at 9:44pm
Because A's constructor does start before T's, but T's ends before A's
May 16, 2013 at 10:14pm
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
A's ctor starts before T's because as soon as it starts it calls T's ctor.
May 17, 2013 at 12:17am
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: 12