In chapter 11 of Accelerated C++ the authors give a careful analysis of requirements for a template class called Vec, which is a simplified version of the standard vector template class, and by stepwise refinement they synthesize a class definition that provides the required services. Some of the main points and technical issues discussed in class include the role of the explicit keyword on class constructors; typedefs to make available associated types according to a consistent set of conventions; overloading of member functions based on const or nonconstness; compiler-synthesized versus user-defined copy constructors, assignment operators, and destructors (see the "rule of three" stated on p. 202); and the distinction between initialization and assignment. In studying this chapter it may be helpful also to look again at the more complete (but still somewhat simplified) definition of a vector class that was shown in the 9/7/2001 lecture. |