- A default constructor is created for every class that does not define one.
- The compiler-created default constructor provides explicit default initializers for each data member declared within the class
- member class object with default constructor
- base class with default constructors
- class with the virtual function
- virtual base class mechanism for each object
case 1:
class Foo { public: Foo(), Foo(int) ...};
class Bar { public: Foo foo; char *str;};
void foo_bar(){
Bar bar; // Bar::foo must be initialized here
if ( str ) {} ...
}
The created default constructor contains the code necessary to invoke the class Foo default constructor on the member object Bar::foo, but it doesn't generate any code to initialize Bar::str. If there are multiple class member objects, it inserts code within each constructor, invoking the associated default constructors for each member in the order of member declaration.
case 2: the created default constructor of the derived class invokes the default constructor of each of its immediate base classes in the order of their declaration.
No comments:
Post a Comment