. hpp files in C + +

Source: Internet
Author: User

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

HPP, the essence of which is to mix the. CPP implementation code in the. h header file, where the definition and implementation are contained in the same file , the caller of the class needs to include the HPP file only, eliminating the need to add CPP to project for compilation.

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

Using HPP will drastically reduce the number of CPP files and compile times in project, as well as the annoying Lib and DLL releases, making it ideal for writing common open source libraries .

1, is the header plus plus the shorthand. 2, similar to *.h ,hpp is a C + + program header file . 3, is the VCL dedicated header file, has been precompiled. 4, is the general template class header file. 5, generally speaking,*.h inside only declaration, did not realize , and *. HPP declarations are implemented, the latter can reduce the number of. cpp . 6, *.h inside can have using namespace std, but *.hpp inside is none.

*.HPP issues to be aware of are:

A) cannot contain global objects and global functions

Since HPP is essentially a. h callee, there are global objects or global functions in the HPP file that, when used by multiple callers, will cause symbolic redefinition errors when linked. To avoid this situation, you need to remove the global object and encapsulate the global function as a static method of the class.

b) Non-cyclic invocation between classes

In the. h and. CPP scenarios, when there is a circular call relationship between two classes or classes, the declaration of the called class is made only in advance in the header file

c) Do not use static members

The limitation of the use of static members is that if a class contains static members, it is necessary to include static member initialization code in HPP, which produces symbolic redefinition errors when the HPP is included in multiple documents.

. hpp files in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.