Derived Classes
Volume Number: 10
Issue Number: 9
Column Tag: Getting Started
C++, Derived Classes, and ObjectMaster
By Dave Mark, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
Back in January’s column, we took a look at some of the basic concepts behind
C++. We talked about objects, and the fact that the variables you’d find in a C program
are called objects in a C++ program. We talked about classes, and the class and struct
keywords used to declare them. We talked about data members, the fields found in a
class, and member functions, the functions associated with a class.
We talked about the different methods of creating an object, from declaring an
object to creating one in the heap using the new operator. We also covered the delete
operator, used to free up the memory used by an object. We talked about constructors
and destructors, the member functions that are called when an object is created and
destroyed.
We also talked about the public and private access specifiers, used to determine
whether a non-member function has access to a specific class member.
If any of these topics make your eyes roll up in their sockets, take a look back at
the January ‘94 C++ column. If you don’t have the January issue, you can order a
back-issue from MacTech...
In this month’s column, we’ll take all this one step further. We’ll take a look at
class derivation, the technique of basing a new class on an existing class. We’ll also
learn about ObjectMaster, a cool tool that makes derived classes a lot easier to work
with.
Even if you’ve already read “Learn C++ on the Macintosh”, keep reading. Though
the beginning of this column covers some material you’ve seen in the chapter on
Derived Classes, this column has a lot of new stuff in it. Most importantly, this
month’s sample program shows you how to set up a multi-file C++ program,
something that “Learn C++” never did...
Derived Classes
C++ allows you to use one class declaration, known as a base class, as the basis
for the declaration of a second class, known as a derived class. Suppose you had a class
called CPushButton that implemented a simple push- button, like the one shown in
Figure 1.
Figure 1. Simple push- button.
The CPushButton class definition might look something like this: