TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  ORG#004

Synopsis:Classes that are only accessed via pointers (*) or references (&) shall not be included as header files
Severity Level:8
Category:Code Organization


When a class contains pointers or references to other classes, the header files of these referenced classes need not be included in the header file defining the containing class. The implementation file belonging to the containing class does of course need the header file with the referenced classes. By doing so, code using the containing class does not depend on the definition of the referenced classes. This limits dependencies and speeds up the building process.

The here-described usage is explained with an example. Suppose that class CDemo, defined in header file Demo.h, contains a pointer to Class CUsed and a reference to class COther defined in files Used.h and Other.h. Then file Demo.h would look like:


class CUsed;
class COther;

class CDemo


    CUsed*  m_pUsed;
    COther& m_rOther;

Since the implementation file of class CDemo makes use of classes CUsed and COther, this file does need to include the corresponding header files and thus the first part of this implementation file looks like:


#include "......"
#include "Used.h"
#include "Other.h"
#include "Demo.h"

Note that this rule also holds for function results of class type.

Literature References:
Ellemtel Rule 9