In a derived class constructor, an initialization list can be used to explicitly call a base class constructor that takes arguments.An initialization list can be used to explicitly call a constructor that takes arguments for a data member that is an object of another class (see the employee constructor example above).Data members that are references must be initialized using an initialization list.Data members that are const but not static must be initialized using an initialization list.For more information, see Static Constructors. There are also several instances in C++ where the use of an initializer list to initialize a data member is actually required: Non-static classes should also define a static constructor if the class contains static members that require non-trivial initialization. Using initialization lists to initialize data members in a constructor can be convenient if you don't need to do any error-checking on the constructor arguments. That is, the compiler knows which month belongs to the object, and which month is the local variable that is declared in the member function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |