From Google
Http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Classes
1. Use # define to prevent repeated inclusion
If the header file is under the bar of the Project Foo folder and the header file name is Baz. H, it is defined as follows:
#ifndef FOO_BAR_BAZ_H_#define FOO_BAR_BAZ_H_...#endif // FOO_BAR_BAZ_H_
2. If the pre-declaration can solve the dependency, do not use the header file to include (kiss)
//#include "otherclass.h"//#include "anohterclass.h"class OtherClass;class AnotherClass;class Sample{ OtherClass * m_pOhter; AnotherClass * m_pAnother; static OtherClass m_sOther; const OtherClass & m_other; void Use(OtherClass po);};
In both cases, you can use the pre-declaration to solve the dependency, because you do not need to know the definition and size of other classes when compiling the sample. Do not include the header file in the header file, unless you have to (inheritance, etc.). Of course, you can include the header file in the. CC file.
3. inline functions
A small inline can reduce the entire size of the program, and vice versa. Suggestion: if there are more than 10 rows of functions, it is better not to inline them. If there are loops and branches in the inline, it is better not to inline, it is not cost-effective.
4,-inL. h header file
Some implementation code can be put here, but do not participate in compilation as CPP alone (only code that is included by some CPP and indirectly involved in compilation can be successful ).
Some C/C ++ coding suggestions for Misra:
Save as (ZIP)
Http://hi.csdn.net/attachment/201202/23/0_13300094632KhX.gif