184 Introduction to C++ Programming and Graphics
The source file “clrunner.cc” contains the class implementation:#include<iostream>
#include<string>
using namespace std;//--- CLASS DEFINITIONclass runner
{
public:
...
private:
...
};//--- CLASS IMPLEMENTATIONrunner::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.ccTo compile the program and create the executable named “runnerfast”, we
issue the command:
make runnerfastand then hit the
Note that the “include” statement:#include "clrunner.h"