Class Destructors 435
What Is a Destructor? 436
The Default Destructor 436
Destructors and Dynamic Memory Allocation 438
Implementing a Copy Constructor 442
Sharing Memory Between Variables 444
Defi ning Unions 444
Anonymous Unions 446
Unions in Classes and Structures 446
Operator Overloading 446
Implementing an Overloaded Operator 447
Implementing Full Support for a Comparison Operator 450
Overloading the Assignment Operator 454
Overloading the Addition Operator 459
Overloading the Increment and Decrement Operators 463
Overloading the Function Call Operator 465
The Object Copying Problem 466
Avoiding Unnecessary Copy Operations 466
Applying Rvalue Reference Parameters 470
Named Objects are Lvalues 472
Class Templates 477
Defi ning a Class Template 478
Creating Objects from a Class Template 481
Class Templates with Multiple Parameters 483
Templates for Function Objects 486
Using Classes 486
The Idea of a Class Interface 486
Defi ning the Problem 487
Implementing the CBox Class 487
Organizing Your Program Code 508
Naming Program Files 509
Native C++ Library Classes for Strings 510
Creating String Objects 510
Concatenating Strings 512
Accessing and Modifying Strings 516
Comparing Strings 520
Searching Strings 523
C++/CLI Programming 533
Overloading Operators in Value Classes 534
Overloading the Increment and Decrement Operators 540
Overloading Operators in Reference Classes 540
Implementing the Assignment Operator for Reference Types 543
Summary 544