Declaring and Defining Destructors . . . . . . . . . . . . . . . . . . . . . 308
Declaring and Defining Copy Constructors . . . . . . . . . . . . . . . . 309
Overloading the Assignment Operator . . . . . . . . . . . . . . . . . . 313
Introducing the Game Lobby Program . . . . . . . . . . . . . . . . . . . . . 315
The Player Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
The Lobby Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
The Lobby::AddPlayer() Member Function . . . . . . . . . . . . . . . . 320
The Lobby::RemovePlayer() Member Function . . . . . . . . . . . . . 322
The Lobby::Clear() Member Function . . . . . . . . . . . . . . . . . . . . 322
The operator<<() Member Function . . . . . . . . . . . . . . . . . . . . 323
The main() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
Questions and Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Discussion Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Chapter 10 Inheritance and Polymorphism: Blackjack ............ 331
Introducing Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Introducing the Simple Boss Program . . . . . . . . . . . . . . . . . . . 333
Deriving from a Base Class . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Instantiating Objects from a Derived Class . . . . . . . . . . . . . . . . 336
Using Inherited Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Controlling Access under Inheritance . . . . . . . . . . . . . . . . . . . . . . 337
Introducing the Simple Boss 2.0 Program . . . . . . . . . . . . . . . . . 338
Using Access Modifiers with Class Members . . . . . . . . . . . . . . . 339
Using Access Modifiers when Deriving Classes . . . . . . . . . . . . . 340
Calling and Overriding Base Class Member Functions . . . . . . . . . . 340
Introducing the Overriding Boss Program . . . . . . . . . . . . . . . . 341
Calling Base Class Constructors . . . . . . . . . . . . . . . . . . . . . . . . 343
Declaring Virtual Base Class Member Functions . . . . . . . . . . . . 344
Overriding Virtual Base Class Member Functions . . . . . . . . . . . 344
Calling Base Class Member Functions . . . . . . . . . . . . . . . . . . . . 345
Using Overloaded Assignment Operators and
Copy Constructors in Derived Classes . . . . . . . . . . . . . . . . . . . . . . 346
Introducing Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
Introducing the Polymorphic Bad Guy Program . . . . . . . . . . . . 347
Using Base Class Pointers to Derived Class Objects . . . . . . . . . . 350
Defining Virtual Destructors . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Using Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Introducing the Abstract Creature Program . . . . . . . . . . . . . . . 352
xvi Contents