To make a class a separate module, put the class into the header file. Do not put the definitions of the functions in the class. Put the function definitions into the implementation file.
#include "random.h"Use this line in any file that needs to use the things described in random.h. Important: Be sure to include random.h in the implementation file random.cc or random.cpp. Each implementation module always includes its own header file.
COMPILE = g++ -c -Wall -O -Wshadow LINK = g++ pi: pi.o random.o $(LINK) -o pi random.o pi.o pi.o: pi.cc random.h $(COMPILE) pi.cc random.o: random.cc random.h $(COMPILE) random.cc clean: rm random.o pi.o piThe lines that define COMPILE and LINK tell what $(COMPILE) and $(LINK) are replaced by. Compiling with option -c creates a file that is not executable, but that is prepared to link to other files. For example, running command
g++ -c random.cccreates file random.o. You cannot run random.o, but you can link it into another program. The g++ compiler will link for you, as you can see in the makefile.
Each item that you build (pi, pi.o, random.o) is a target in the makefile. The target is followed by a colon, and then a list of the files that are used in building it. After that is a command (or several commands) with a tab in front of it (or in front of each one, if there are several). The command is used to build the target. It is very important to begin each command line with at tab.
To build a target t, type command
make tYou can build the first target in the makefile by just typing command
makeNormally, you put the target that you most often build first, so that you can use this abbreviated command.
The target clean has been defined so that you can type
make cleanto remove all of the machine-generated files. If you move from one kind of computer to another, for example, you probably want to make your implementation clean and recompile.