/************************************************************************ *
The following code fragment shows two classes with constructors,
default constructors, and copy constructors:
class X { public: X(); // default constructor, no arguments X(int, int , int = 0); // constructor X(const X&); // copy constructor X(X); // error, incorrect argument type }; class Y { public: Y( int = 0); // default constructor with one // default argument Y(const Y&, int = 0); // copy constructor };
When more than one base class exists, the base class constructors
are called in the order that their classes appear in the base list, as
shown in the following example:
* ************************************************************************/
class B1 { public: B1(); }; class B2 { public: B2(); B1 b1obj; }; class B3 { public: B3(); }; // ... class D : public B1, public B2, public B3 { public: D(); ~D(); }; void main () { D object; }
/************************************************************************ *
In the above example, the constructors for object are called in the
following order:
B1(); // first base constructor declared B1(); // member constructor for B2::b1obj B2(); // second base constructor declared B3(); // last base constructor declared D(); // derived constructor called last
Note that the construction of class D involves construction of the base classes B1, B2, and B3. The construction of base class B2 involves the construction of its class B1 member object. When class B2 is constructed , the constructor for class B1 is called in addition to B2's own constructor.
As explained above, the second call to the constructor
of B1 followed by the call to the constructor of B2 is part of the
construction of B2.
* ************************************************************************/