October 2011
Beginner to intermediate
1200 pages
35h 33m
English
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 ...
Read now
Unlock full access