C + + places the declaration and definition of a template in the same header file

Source: Internet
Author: User

1. A class: The header file is used to hold the declaration of the class, and the implementation of the file save class is defined. 2. Detach Compilation mode: Allows you to define functions, types, class objects, and so on in a single compilation unit (. cpp file), and then reference them in another compilation unit. When the compiler finishes processing all the compilation units, the linker then processes all references to the extern symbol (sometimes by default), resulting in a single executable file. 3. Template type: The template type is not a real type, it must wait until the type is bound to determine the final type, so when instantiating a template, you must be able to let the compiler "see" where the template is used, and must see the exact definition of the template, not just their declaration, otherwise it will not be able to produce the compiled code successfully. Therefore, the standard requires that the instantiation of the template and the definition body be placed in the same compilation unit.
// Temp.htemplate <class t>class  temp{public:      void Set_value (const t& RT); protected : Private :     <class t>void temp<t>::set_value (const t& RT) {    = RT;}

C + + places the declaration and definition of a template in the same header file

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.