Separate Compilation
All source code does not need to be contained within a single file.
C++ conventions are to place the following in header (or .h) files:
Constant definitions
Type definitions
Class definitions
Function prototypes
Macros (i.e., #define)
C++ conventions are to place executable source code, which is typically the implementation of functions and classes defined in the header files in source (or .cpp) files. Additionally, all applications which use class implementations appear in source files.
Example (see here)
In creating the class complex_numbers, we put the class definition in complex.h (a header file)
The implementation of the class appears in complex.cpp (a source file)
The application appears in complex_app.cpp (a source file)
Under linux we build the example application as below. The first line compiles the class implementation creating complex.o. The second line compiles the application creating complex_app.o. The third line links the two object files together (with other system libraries) to create the executable program app.
g++ -c complex.cpp
g++ -c complex_app.cpp
g++ -o app complex_app.o complex.o
Under Visual C++ all source created within the same project is automatically linked together in the same build unless specifically excluded.