Must the definition of a generic function be written in the header file?

Source: Internet
Author: User

"Compiling"
Templates requires maintenance ance from the programming environment.
Language defines two broad strategies for instantiating templates:
Dimensional Model and the separate compilation model. These models have
Imptts on how we build our systems in so far as they dictate whether
Template definitions go in header files or source files. At this time,
All impilers implements the compression sion model, while only some implement
The separate compilation model. Your Compiler's User's Guide shoshould
Specify how your system manages templates ."

This is a piece of code derived from C ++ primer. compiling a template requires the support of the compiler. The language provides two policies for template instantiation: including the model and compiling the model separately. These models determine whether the template definition should be placed in the header file or the source file. All the compilers implement include models, while only a few compilers compile models separately.

Therefore, the definition of generic functions does not have to be written in the header file. However, if you use C ++ to write generic functions, write the function definition in the header file.

previously, I noticed this problem using the model. I will record it for the time being, and stay in the future for further research.

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.