Special Relationships Between Derived and Base Classes
A derived class has some special relationships with the base class. One, which you’ve just seen, is that a derived-class object can use base-class methods, provided that the methods are not private:
RatedPlayer rplayer1(1140, "Mallory", "Duck", true);rplayer1.Name(); // derived object uses base method
Two other important relationships are that a base-class pointer can point to a derived-class object without an explicit type cast and that a base-class reference can refer to a derived-class object without an explicit type cast:
RatedPlayer rplayer1(1140, "Mallory", "Duck", true);TableTennisPlayer & rt = rplayer;TableTennisPlayer * pt = &rplayer;rt.Name(); // invoke Name() with reference ...
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.