Why are destructors called in reverse?

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


@LB

Why?
Because A's constructor does start before T's, but T's ends before A's
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...
A's ctor starts before T's because as soon as it starts it calls T's ctor.
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