-->

Previous | Table of Contents | Next

Page 484

New C++ classes (and hence datatypes) can be defined so that they automatically inherit the properties and algorithms associated with their parent classes. This is done whenever a new class uses any of the standard C datatypes. The class from which new class definitions are created is called the base class. For example, a structure that includes integer members will also inherit all the mathematical functions associated with integers. New classes that are defined in terms of the base classes are called derived classes. The Circle class in Listing 23.15 is a derived class.

Derived classes can be based upon more than one base class, in which case the derived class inherits multiple datatypes and their associated functions. This is called multiple inheritance.

Because functions can be overloaded, it is possible that an object declared as a member of a derived class might act differently than an object of the base class type. For example, the class of positive integers might return an error if the program attempts to assign a negative number to a class object, although such an assignment would be legal with regard to an object of the base integer type.

This ability of different objects within the same class hierarchy to act differently under the same circumstances is referred to as polymorphism. Polymorphism is the object-oriented concept that many people have the most difficulty grasping. However, it is also the concept that provides much of the power and elegance of object-oriented design and code. A programmer designing an application using predefined graphical user interface (GUI) classes, for instance, is free to ask various window objects to display themselves appropriately without having to concern herself with how the window color, location, or other display characteristics are handled in each case.

Class inheritance and polymorphism are among the most powerful object-oriented features of C++. Together with the other less dramatic extensions to C, these features have made possible many of the newest applications and systems capabilities of UNIX today, including GUIs for user terminals and many of the most advanced Internet and World Wide Web technologies—some of which will be discussed in the subsequent chapters of this book.

GNU C/C++ Compiler Command-Line Switches

There are many options available for the GNU C/C++ compiler. Many of them match the C and C++ compilers available on other UNIX systems. Table 23.7 shows the important switches; look at the man page for gcc or the info file on the CD-ROM for the full list and description.

Table 23.7. GNU C/C++ compiler switches.


Switch Description
-x language Specifies the language (C, C++, and assembler are valid values)
-c Compiles and assembles only (does not link)
-S Compiles (does not assemble or link)

Page 485


Switch Description
-E Preprocesses only (does not compile, assemble, or link)
-o file Specifies the output filename (a.out is the default)
-l library Specifies the libraries to use
-I directory Searches the specified directory for include files
-w Inhibits warning messages
-pedantic Strict ANSI compliance required
-Wall Prints additional warning messages
-g Produces debugging information (for use with gdb)
-p Produces information required by proff
-pg Produces information for use by groff
-O Optimizes

Additional Resources

If you are interested in learning more about C and C++, you should look into the following books:

Summary

UNIX was built upon the C language. C is a platform-independent, compiled, procedural language based on functions and the ability to derive new, programmer-defined data structures.

C++ extends the capabilities of C by providing the necessary features for object-oriented design and code. C++ compilers correctly compile ANSI C code. C++ also provides some features, such as the ability to associate functions with data structures, which don't require the use of full class-based, object-oriented techniques. For these reasons, the C++ language allows existing UNIX programs to migrate toward the adoption of object orientation over time.

Page 486

Previous | Table of Contents | Next