TOPIC 12.3.2
Dividing Source Code for Classes


The #include statement is a preprocessor directive. Meaning it is processed before the program is actually compiled. It is good to remember that the #include directive is an instruction to the compiler rather than part of the C++ language, and instructs the compiler to treat the text file that is enclosed as if it were keyed into the source code. This is how the class prototype can be contained in the header file and be implemented in a cpp file. An example of this is show below.

    Header File: circle.h

    Implementation File: circle.cpp

You must include the header file in the implementation file using the #include directive.

To use these files in a program, you must do one of several things:

  1.     You can include the header file in your program using the #include directive ...
  2.     or you can include the implementation file in your program using the #include directive.

If you choose to include the header file, you must add the implementation file to the project also.  The way you do this varies between compilers.  In Microsoft's Visual C++ 5.0, you simply select "Add to Project" under the "Project" menu, then select "Files ...."  Then open the file you wish to add (in this case circle.cpp).