Initializing data members
There are two ways to initialize data members.
- Explicit assignments in a constructor.
- In a member initializer in the constructor header.
Member initializer syntax
The definition (not the prototype) header is followed by a colon, the name of the field, and a parenthesized initial value. Separate multiple initializations with commas.
Insert example here
Member initializer required in the following cases
- To initialize
const
data members. - To initialize references.
- To initialize member objects. If a member initializer is not provided, the default constructor for that class will be called.
- To initialize base class members.
No comments:
Post a Comment