Contents|Index|Previous|Next
 Declarations and definitions in one header   

C++ object definitions can be quite complex. In principle, your source code will need two kinds of things for each object that you use across more than one source file.

First, you need an interface specification, describing its structure with type declarations and function prototypes. Second, you need the implementation itself. It can be tedious to maintain a separate interface description in a header file, in parallel to the actual implementation. It is also dangerous, since separate interface and implementation definitions may not remain parallel. With GNU C++, you can use a single header file for both purposes.

The header file contains the full definitions, but is marked with ‘#pragma interface’ in the source code. This allows the compiler to use the header file only as an interface specification when ordinary source files incorporate it with #include. In the single source file where the full implementation belongs, you can use either a naming convention or ‘#pragma implementation’ to indicate this alternate use of the header file.

Top|Contents|Index|Previous|Next