Constructors: Access Considerations
A derived class does not have direct access to the private members of the base class; it has to work through the base-class methods. For example, the RatedPlayer
constructors cannot directly set the inherited members (firstname
, lastname
, and hasTable
). Instead, they have to use public base-class methods to access private base-class members. In particular, the derived-class constructors have to use the base-class constructors.
When a program constructs a derived-class object, it first constructs the base-class object. Conceptually, that means the base-class object should be constructed before the program enters the body of the derived-class constructor. C++ uses the member initializer list syntax to accomplish ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.