Separation of template method definition and declaration during Template Class Definition

Source: Internet
Author: User

C ++ primer plus:

"Because templates are not functions, they cannot be compiled independently and must be used together with specific template instantiation requests. To do this, the easiest way is to put all template information in a header file and include this header file in the file to use these templates ."

"If the compiler implements the new export keyword, you can place the template method definition in an independent file, provided that each template declaration starts with export:

...... (Omitted)

Export template <class type>

Class Stack

{

...

};

Then follow the regular class method:

1. Place the template declaration (including the keyword export) in a header file and use the # include commandProgramThese statements can be used.

2. Place the method definition of the template class inSource codeFiles that contain header files and use engineering files (or other equivalent files) to enable programs to use these definitions.

"

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.