Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - base class initialization http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Base Class Initialization
   The  use of a member initialization list with class  constructors  has
   been discussed earlier under Constructors and Destructors. This syntax
   is  extended to allow the initialization of base classes  through  the
   derived  class constructor. The syntax is the same as that for  member
   initialization,  the  base  class  identifier  being  followed  by  an
   argument  list in parentheses. This argument list is passed on to  the
   base class constructor which is called before the body of the  derived
   class  constructor is executed. In the case of multiple base  classes,
   each  may  be included in the  comma-separated  member  initialization
   list.  If  the  base class has no constructor or  a  constructor  that
   requires no arguments or one that has all arguments defaulted, it need
   not be specified in the member initialization list.

   Constructors for classes in the initialization list are called in  the
   order  they  occur in the list, from left to right.  Constructors  for
   class  members are called after all base class constructors have  been
   executed. The body of the derived class constructor is executed  last.
   This order is applied recursively for each constructor.

   Example:
   Derived::Derived(int ct, char *ptr, long val, char status, short tp) :
   base1(ct, val), base2(tp, ptr)
   {
   ;// derived constructor code here
   }
   A base class can be initialized with an object of the base class, or a
   class  which has been publicly derived from it. The default,  or  user
   provided, X::X(const X&) constructor for the class will be used, e.g.

   Derived::Derived(int ct, Derived& dc) : Base(dc)
   {
   ;// derived constructor code here
   }

   It  is  illegal explicitly to initialize a base class  member  in  the
   member initialization list. The base class constructor has that role.


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson