.hpp file in c++

http://blog.chinaunix.net/uid-24118190-id-75239.html

hpp, the essence of which is to mix the implementation code of .cpp into the .h header file, and the definition and implementation are included in the same file , then the caller of this class only needs to include the hpp file, no need to add cpp to the project. to compile.

The implementation code will be compiled directly into the caller's obj file, and no separate obj will be generated.

Using hpp will greatly reduce the number of cpp files and compilation times in the calling project, and will no longer release annoying lib and dll, so it is very suitable for writing public open source libraries .

 

1. It is the abbreviation of Header Plus Plus.
2. Similar to *.h , hpp is a C++ program header file .
3. It is a special header file for VCL, which has been precompiled.
4. It is the header file of the general template class.
5. Generally speaking, there are only declarations in *.h, but no implementations , while * .hpp contains declarations and implementations, which can reduce the number of .cpps .
6. There can be using namespace std in *.h, but not in *.hpp.

 

*.hpp should pay attention to the following issues:

      a) cannot contain global objects and global functions

     Since hpp is essentially included as a .h callee, when there is a global object or global function in the hpp file, and the hpp is included by multiple callers, it will cause a symbol redefinition error at link time. To avoid this, you need to remove the global object and encapsulate the global function as a static method of the class.

      b) No circular calls between classes

      In the scenarios of .h and .cpp, when there is a cyclic calling relationship between two classes or multiple classes, just declare the called class in the header file in advance.

  c) Static members cannot be used 

      The limitation of the use of static members is that if the class contains static members, the static member initialization code must be added to the hpp. When the hpp is included by multiple documents, a symbol redefinition error will occur.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272042&siteId=291194637