How to Use a Class Library

There are several ways to use a C++ class library:

Construct objects directly from the classes provided

Derive new classes

Modify the class source code

Direct Use of Classes and Objects

Many class libraries provide classes that support the direct construction of useful objects. Some even construct the objects for you prior to the execution of your main program.

The iostream Class Library includes the predefined objects cout and cin. Many developers use those objects directly, and others construct their own objects from the classes such as ifstream and ostrstream.

In the Microsoft Foundation Class Library, some classes, such as those dealing with strings, time, and some low-level Windows functions, are most often used directly for the construction of objects.

Derivation of New Classes

Certain classes are designed for the purpose of derivation. CObject, the root class for most Microsoft Foundation Classes, is an example of a class that is not meant to be used directly. Likewise, the CWnd window class (for Microsoft Windows) is generally used as a base class for customized windows. A CWnd object can display itself and handle basic messages, but it doesn't show or accept data. A derived class can provide the mouse and keyboard notification message functions that make the window part of an application.

Other classes can be used directly or they can be derived from in order to add new functionality. In the Microsoft Foundation Classes tutorial, you will see how a special-purpose CPersonList class can be derived from the generic Microsoft Foundation Library CObList class. The derived class adds new data members and member functions.

Modification of Class Source Code

Sometimes you can't achieve all your customization objectives by class derivation. You may, for example, need access to a private data member. If you have the library source code, you can modify the class directly. Even if you don't modify the class, the source code is a useful learning and debugging resource.

The source code for the Microsoft Foundation Class Library is provided. The source code for the Microsoft iostream Class Library is available separately.