184 Introduction to C++ Programming and Graphics
The source file “clrunner.cc” contains the class implementation:
#include<iostream>
#include<string>
using namespace std;
//--- CLASS DEFINITION
class runner
{
public:
...
private:
...
};
//--- CLASS IMPLEMENTATION
runner::runner()
{
time = 2000.0;
}
...
double runner::gettime() const
{
return time;
}
A makefile that compiles separately the main function and the class, and
then links the object files to generate the executable is structured as follows:
runnerfast: clrunner.o runnerfast.o
c++ -o runnerfast clrunner.o runnerfast.o
runnerfast.o: runnerfast.cc
c++ -c runnerfast.cc
clrunner.o: clrunner.cc clrunner.h
c++ -c clrunner.cc
To compile the program and create the executable named “runnerfast”, we
issue the command:
make runnerfast
and then hit the
Note that the “include” statement:
#include "clrunner.h"