Compile template instantiation

Source: Internet
Author: User

If there is a common definition of the template in the header file, and the header file is contained in multiple places, multiple compiled copies of the template will be created. This is certainly possible, but in large programs with multiple templates, all target files contain copies of each compiled template, which makes the compilation time very long and the target file is large,

Here are some optional scenarios:

1, in the source file, using the indicator Word #pragma interface and #pragma implementation, will only create a compiled template.

2, similar to the use of two Prama, use the command line option-falt-external-templates compile all the source files. This tells the compiler to include the compiled template instance only when the module is actually used. An important feature of this approach is that the header files must be the same for each module that uses the head file.

3. Compile the code with the command-line option-frepo, so that the file suffix created is. RPO, and each. rpo file lists the template instances in the corresponding destination file. The Connection Pack tool Collect2 is then activated to update the. rpo file, which instructs the connector to replace the template instance in the last program. This approach is only difficult when working with libraries---unless the associated. rpo files are present, the template instances in the connection library will fail.

4, compile the code with-fno-implicit-templates, will make the implicit template instantiation invalidation, he will display the initialization of the required template. While this approach requires a precise understanding of which template instance is being used, this approach does make the source code clearer.

Compile template instantiation

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.