Prev Up Next
Go backward to 10/15/2001   A Larger Example of Literate Programming
Go up to News Archive
Go forward to 10/5/2001   Simplified Vector Class Used to Illustrate Important Principles in Defining Abstract Data Types

10/12/2001   Simplified String Class Illustrates Principles of Making Class Objects Behave as Values

 AP Wire Service
In chapter 12 of Accelerated C++ the authors develop a class called Str, which is a simplified version of the standard string class, and in doing so they illustrate several important principles of abstract data type definition. The main focus is on supporting implicit conversions to and from other types. By defining appropriate constructors one can support implicit conversions from other types into Str objects, and by defining conversion operators one can support implicit conversions from Str objects into other types. The authors show how the role of such conversions dictates other design decisions, such as whether some operator definitions are defined as member or nonmember functions. They also explain why in some cases it not desirable to provide conversion operators, since doing so could result in memory leaks or other hard-to-understand errors.

 

Prev Up Next