1, avoid the header file repeat contains
TEST.H This macro means that if a macro variable is defined Test_h_ it is no longer defined #ifndef test_h_#define test_h_//header file Contents #endif
Or
Test.h tells the precompiled compiler to include only one #pragma once
2. Avoid duplicate definitions
Do not put the function definition in the header file, the correct way is to put the header file function declaration, the source file placement function definition. Because the source file is compiled separately, if the header file has a function definition, each source file containing the header will define the corresponding function, resulting in a duplicate definition. However, there are several exceptions: the definition of an inline function, the definition of a class, the const and static variables, and the template class/function requirement that the header file must contain a definition before it can be templated.
3. Avoid the inclusion and circulation of header files
Header files containing each other lead to recursive inclusion, the logic of the dependency of the header file itself is wrong and cannot be implemented, the header file loop contains the same (such as A.H contains B.h,b.h contains c.h,c.h contains a.h). The correct way is to minimize the dependency of the header file, try to include the header file in the source file, the header file as far as possible with the predecessor declaration (use pointers and references as far as possible, the relevant definitions are placed in the source file medium). A pre-declared class is an incomplete type, and an incomplete type can only be used in a limited way. An object of this type cannot be defined. A non-full type can only be used to define pointers and references to that type, or to declare (rather than define) a function that uses that type as a formal parameter type or return type.
This article is from the "Haopeng Li blog" blog, please be sure to keep this source http://lh2debug.blog.51cto.com/12490788/1890170
C + + function duplicate definition, header file duplicate inclusion, mutual inclusion problem