* appu:
Suppose class A is inherited from class B and Class B is inherited
from class C. Could anyone explain on how the C++ compiler construct
the A object and how is A object destroyed by compiler when it is out
of scope. Can anyone explain what does the compiler do in these
process?
This seems like a HOMEWORK question rephrased for clc++.
Please read the FAQ items about how to post, and about HOMEWORK questions.
That said, what the compiler does is irrelevant to the question of
construction and destruction. In particular, the compiler does not
construct objects, as you seem to think it does. The compiler
translates your C++ source code to executable form.
Only what happens in the program is relevant with respect to object
construction and destruction.
And one easy way you can check up on that (I'm not going to give you the
conclusions, since this is most likely HOMEWORK) is to embed output
statements in the constructors and destructors for classes A, B and C.
Although that will not tell you the full story, it will provide a good
starting point for understanding things.
What's left to understand when you have done the above (just ask here if
you run into difficulties): the order of execution for initializer list
expressions, what happens with virtual inheritance, what happens when a
constructor throws an exception, what happens with initialization of
arrays, ditto when a constructor for an array element throws, what
happens with virtual calls from constructors, under what conditions &
when can *this be used during construction, & more... Enjoy your
research into these matters. And again, just ask if you need, but then,
please post the C++ CODE (copy and paste), what your expectations were,
why you expected that, and what actually happened that was unexpected.
Cheers, & hth.,
- Alf