In this chapter, we continue our study of classes and data abstraction with several more advanced topics. We use const objects and const member functions to prevent modifications of objects and enforce the principle of least privilege. We discuss compositiona form of reuse in which a class can have objects of other classes as members. Next, we introduce friendship, which enables a class designer to specify non-member functions that can access class's non-public membersa technique that is often used in operator overloading (Chapter 11) for performance reasons. We discuss a special pointer (called this), which is an implicit argument to each of a class's non-static member functions that allows those member functions to access the correct object's data members and other non-static member functions. We then discuss dynamic memory management and show how to create and destroy objects dynamically with the new and delete operators. Next, we motivate the need for static class members and show how to use static data members and member functions in your own classes. Finally, we show how to create a proxy class to hide the implementation details of a class (including its private data members) from clients of the class.
Recall that Chapter 3 introduced C++ Standard Library class string to represent strings as full-fledged class objects. In this chapter, however, we use the pointer-based strings we introduced in Chapter 8 to help the reader master pointers and prepare for the professional world in which the reader will see a great deal of C legacy code implemented over the last two decades. Thus, the reader will become familiar with the two most prevalent methods of creating and manipulating strings in C++.
Introduction to Computers, the Internet and World Wide Web
Introduction to C++ Programming
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Functions and an Introduction to Recursion
Arrays and Vectors
Pointers and Pointer-Based Strings
Classes: A Deeper Look, Part 1
Classes: A Deeper Look, Part 2
Operator Overloading; String and Array Objects
Object-Oriented Programming: Inheritance
Object-Oriented Programming: Polymorphism
Templates
Stream Input/Output
Exception Handling
File Processing
Class string and String Stream Processing
Web Programming
Searching and Sorting
Data Structures
Bits, Characters, C-Strings and structs
Standard Template Library (STL)
Other Topics
Appendix A. Operator Precedence and Associativity Chart
Appendix B. ASCII Character Set
Appendix C. Fundamental Types
Appendix D. Number Systems
Appendix E. C Legacy Code Topics
Appendix F. Preprocessor
Appendix G. ATM Case Study Code
Appendix H. UML 2: Additional Diagram Types
Appendix I. C++ Internet and Web Resources
Appendix J. Introduction to XHTML
Appendix K. XHTML Special Characters
Appendix L. Using the Visual Studio .NET Debugger
Appendix M. Using the GNU C++ Debugger
Bibliography