Abstract base classes

Classes that act as base classes and not meant to be instantiated are called abstract base classes. Many classes in the Taligent Application Environment, such as TStream, fall into this category. If you have an abstract base class, use two techniques to make that clear:

Make abstract base class constructors protected to ensure that only a derived class can call the constructor, and so that clients can't try to create an object of that class.

NOTE Although you can make destructors private or protected to prevent stack allocation, do not make abstract base class destructors private or protected unless you don't want clients to delete an object given a pointer to a base class. This isn't usually the case. See "Control class access" on page 107 for
more information.

Use pure virtual functions in your abstract class for those functions that must be overridden by derived classes. For example, before you can create a concrete class (one that can be instantiated), you must override this pure virtual function:

      class TAbstract {
      public:
         virtual void MustOverride() = 0;
      };
For more information about virtual functions, see "Virtual functions" on page 66.

NOTE An abstract base class can itself be derived from another class, which might or might not be abstract itself.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker