Main Page

Previous Page
Next Page

[Page 516 (continued)]

9.13. Wrap-Up

This chapter deepened our coverage of classes, using a rich Time class case study to introduce several new features of classes. You saw that member functions are usually shorter than global functions because member functions can directly access an object's data members, so the member functions can receive fewer arguments than functions in procedural programming languages. You learned how to use the arrow operator to access an object's members via a pointer of the object's class type.

You learned that member functions have class scopei.e., the member function's name is known only to other members of the class unless referred to via an object of the class, a reference to an object of the class, a pointer to an object of the class or the binary scope resolution operator. We also discussed access functions (commonly used to retrieve the values of data members or to test the truth or falsity of conditions) and utility functions (private member functions that support the operation of the class's public member functions).

You learned that a constructor can specify default arguments that enable it to be called in a variety of ways. You also learned that any constructor that can be called with no arguments is a default constructor and that there can be a maximum of one default constructor per class. We discussed destructors and their purpose of performing termination housekeeping on an object of a class before that object is destroyed. We also demonstrated the order in which an object's constructors and destructors are called.

We demonstrated the problems that can occur when a member function returns a reference to a private data member, which breaks the encapsulation of the class. We also showed that objects of the same type can be assigned to one another using default memberwise assignment. Finally, we discussed the benefits of using class libraries to enhance the speed with which code can be created and to increase the quality of software.

[Page 517]

Chapter 10 presents additional class features. We will demonstrate how const can be used to indicate that a member function does not modify an object of a class. You will learn how to build classes with compositionthat is, classes that contain objects of other classes as members. We'll show how a class can allow so-called "friend" functions to access the class's non-public members. We'll also show how a class's non-static member functions can use a special pointer named this to access an object's members. Next, you'll learn how to use C++'s new and delete operators, which enable programmers to obtain and release memory as necessary during a program's execution.

Previous Page
Next Page