Constructor call during inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • appu

    #1

    Constructor call during inheritance

    Hi all,
    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?

    thanks in advance

    -karups

  • James Kanze

    #2
    Re: Constructor call during inheritance

    On Oct 6, 2:37 pm, appu <karuppaiah...@ gmail.comwrote:
    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?
    The rule is that the compiler generates calls to the base class
    constructors (using the initialization arguments if there are
    any, and the default constructor otherwise) and all member
    objects before entering into its own body. Thus, in this case,
    the compiler will generate a call to the constructor of B at the
    top of the constructor of A. (The same thing happens with B, of
    course, so the constructor of B calls the constructor of C.)

    Destruction works the same way, except that the calls to the
    base class destructors are at the end of the derived class
    constructor.

    If this isn't described in your basic C++ text, it's time to get
    a different text.

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    Working...