Honne Gowda A wrote:[color=blue]
>
> Hi,
> Can anybody clarify why destruction happens in reverse way?
> for example A<-B<-C, when C's object is constructed, ctor calls will A(),B() and
> C(), when this object is destroyed, sequence of calls will be ~C(),~B(),and
> ~C().[/color]
You mean ~A() :-)
[color=blue]
> I am wondering why cant' we destroy the object like ctor way?..Are there
> any good reasons for this?
>[/color]
Generally it is most always a good idea to undo things in the exact reverese
order that they got done.
But in specific:
Suppose class C is dependent on things in A. For the construction this
is not a problem, since C is constructed after A has finished construction,
so at the time the ctor of C runs, it can access all of A's functionality.
But then destructin happens. Again C has to do work and wants to use information
from A. If A gets destructed first, then that information will not be available
any more. But if the destruction starts at C it can use everything from A needed
to do its job.
--
Karl Heinz Buchegger
kbuchegg@gascad.at