C++ Coding Standard Specification - CERN
C++ Coding Standard Specification - CERN
C++ Coding Standard Specification - CERN
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>C++</strong> <strong>Coding</strong> <strong>Standard</strong><br />
<strong>Specification</strong><br />
3 <strong>Coding</strong> Version/Issue: 1.1/5<br />
#define IDENTIFIER_H<br />
// The text of the header goes in here ...<br />
#endif // IDENTIFIER_H<br />
The actual value for the IDENTIFIER is a project/experiment convention.<br />
Header files are often included many times in a program. Because <strong>C++</strong> does not allow<br />
multiple definitions of a class, it is necessary to prevent the compiler from reading the<br />
definitions more than once.<br />
Source<br />
Status<br />
CXX-9, 7.RC, COMP8, R62, 1. GS, ARC3<br />
Common<br />
CO4<br />
Use forward declaration instead of including a header file, if this is sufficient.<br />
Example:<br />
class Line;<br />
class Point {<br />
public:<br />
Number distance(const Line& line) const; // Distance from a line<br />
};<br />
Here it is sufficient to say that Line is a class, without giving details which are inside its<br />
header. This saves time in compilation and avoids an apparent dependency upon the Line<br />
header file.<br />
Source<br />
Status<br />
CXX-22, R58, 9. RC, 2. GC<br />
Common<br />
CO5<br />
Each header file should contain one class (or embedded or very tightly coupled classes)<br />
declaration only.<br />
This makes easier to read your source code files. This also improves the version control of the<br />
files; for example the file containing a stable class declaration can be committed and not<br />
changed anymore.<br />
CO6<br />
Implementation files should hold the member function definitions for a single class (or<br />
embedded or very tightly coupled classes) as defined in the corresponding header file.<br />
This is for the same reason as for item CO5.<br />
page 14<br />
FINAL