Separate compilation is available with C++ and it follows the identical rules as given for ANSI-C separate compilation. As expected, separately compiled files can be linked together. However, since classes are used to define objects, the nature of C++ separate compilation is considerably different from that used for ANSI-C. This is because the classes used to create the objects are not considered as external variables, but as included classes. This makes the overall program look different from a pure ANSI-C program. Your programs will take on a different appearance as you gain experience in C++.


Once again we come to the practical part of this lesson where we study a practical class that can actually be used in a program but is still simple enough for the student to completely understand.

In the last chapter we studied the date class and in this chapter we will study a simple time class. You should begin by studying the file named TIME.H which will look very similar to the date class header. The only major difference in this class from the date class is the overloaded constructors and methods. The program is a very practical example that illustrates very graphically that many constructor overloading are possible. The header file time.h uses #ifndef and #define directives to define the class as time_of_day.

The implementation for the time class is given in the file named TIME.CPP.

Once again, the code is very simple and you should have no problem understanding this example in its entirety. It should be pointed out that three of the four overloadings actually call the fourth so that the code did not have to be repeated four times. This is a perfectly good coding practice and illustrates that other member functions can be called from within the implementation.

The example program named USETIME.CPP is a very simple program that uses the time class in a very rudimentary way as an illustration for you.

You should be able to understand this program in a very short time. It will be to your advantage to completely understand the practical example programs given at the end of the last chapter and the end of this chapter. As mentioned above, we will use the time class and the date class as the basis for both single and multiple inheritance in the next three chapters.


At this point you have learned enough C++ to write meaningful programs and it would be to your advantage to stop studying and begin using the knowledge you have gained. Because C++ is an extension to ANSI-C, it can be learned in smaller pieces than would be required if you are learning a completely new language. You have learned enough to study and completely understand the example program given in chapter 12, the Flyaway adventure game. You should begin studying this program now.

One of your biggest problems is learning to think in terms of object oriented programming. It is not a trivial problem if you have been programming in procedural languages for any significant length of time. However, it can be learned by experience, so you should begin trying to think in terms of classes and objects immediately. Your first project should use only a small number of objects and the remainder of code can be completed in standard procedural programming techniques. As you gain experience, you will write more of the code for any given project using classes and objects but every project will eventually be completed in procedural code.

After you have programmed for a while using the techniques covered up to this point in the tutorial, you can continue on to the next few chapters which will discuss inheritance and virtual functions.