November 2001
Beginner
1128 pages
29h 12m
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:
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 pt->Name(); // invoke Name() with pointer
However, a base class pointer ...
Read now
Unlock full access