|
|
|
|
|
|
|
Returning to our TimeType class, let's assume we have used the system's editor to create the timetype.h and timetype.cpp files. Now we can compile timetype.cpp into object code. If we are working at the operating system's command line, we use a command similar to the following: |
|
|
|
|
|
|
|
|
In this example, we assume that cc is the name of a command that invokes either the C++ compiler or the linker or both, depending on various options given on the command line. The command-line option -c means, on many systems, compile but do not link. In other words, this command produces an object code file, say, timetype.obj, but does not attempt to link this file with any other file. |
|
|
|
|
|
|
|
|
A programmer wishing to use the TimeType class will write code that #includes the file timetype.h, then declares and uses TimeType objects: |
|
|
|
|
|
|
|
|
#include timetype.h
.
.
.
TimeType appointment;
appointment.Set(15, 30, 0);
appointment.Write();
.
.
. |
|
|
|
|
|
|
|
|
If this client code is in a file named diary.cpp, an operating system command like |
|
|
|
|
|
|
|
|
cc diary.cpp timetype.obj |
|
|
|
|
|
|
|
|
compiles the client program into object code, links this object code with timetype.obj, and produces an executable program (see Figure 15-7). |
|
|
|
|
|
|
|
|
The mechanics of compiling, linking, and executing vary from one computer system to another. The examples we gave using the cc command assume you are working at the operating system's command line. Some C++ systems provide an integrated environmenta program that bundles the editor, the compiler, and the linker into one package. Integrated environments put you back into the editor when a compile-time or link-time error occurs, pinpointing the location of the error. Some integrated environments also manage project files. Project files contain information about all the con- |
|
|
|
|
|