Deriving a Class
Some members of the Webtown Social Club have played in local table tennis tournaments, and they demand a class that includes the point ratings they’ve earned through their play. Rather than start from scratch, you can derive a class from the TableTennisPlayer
class. The first step is to have the RatedPlayer
class declaration show that it derives from the TableTennisPlayer
class:
// RatedPlayer derives from the TableTennisPlayer base classclass RatedPlayer : public TableTennisPlayer{...};
The colon indicates that the RatedPlayer
class is based on the TableTennisPlayer
class. This particular heading indicates that TableTennisPlayer
is a public base class; this is termed public derivation. An object of a derived class incorporates ...
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.