Difference between revisions of "Cpp Coding Standards/HEADERS/Self"
From Apache OpenOffice Wiki
(moved from summary page to details) |
B michaelsen (Talk | contribs) |
||
Line 34: | Line 34: | ||
Param p; | Param p; | ||
p = doSomething1(p); // Error without the definition | p = doSomething1(p); // Error without the definition | ||
+ | [[Category:Coding Standards]] |
Latest revision as of 17:13, 14 December 2009
Self Sufficient and Minimal (Self)
When included, a header file should be self sufficient and minimal.
- Include definitions for superclasses, data members, typedefs, macros, types denoted in exception-specifications, ...
- Create forward declarations for everything else (but note that this introduces unwanted coupling, when for example a template declaration is later on extended with defaulted parameters, or a struct definition is replaced with a typedef)
- Include the definition as late as possible, this helps reduce physical dependencies
// Foo.hxx // Superclass and data member #include "Super.hxx" #include "Data.hxx" // Forward declarations class Param; // This does not need a class definition Param doSomething1(Param aParam); class Foo : public Super { public: // This does not need a class definition either Param doSomething(Param aParam); private: Data mData; };
// Anotherfile.cxx #include "Foo.hxx" #include "Param.hxx" // Now we need the definition ... Param p; p = doSomething1(p); // Error without the definition