CPP templates class templates are localized

Source: Internet
Author: User
Class templates can be localized. The following is an example:

Template <typename T1, typename T2>
Class myclass {
...
}
The following local features are available:
// Localized features: the two template parameters have the same type
Template <typename T>
Class myclass <t, t> {
......
}

// Localized features: the type of the second template parameter is int.
Template <typename T>
Class myclass <t, int> {
...
}

// Localized features: both template parameters are pointer type
Template <typename T1, typename T2>
Class myclass <t1 *, T2 *> {
...
}

The following example shows the template used by various declarations:

Myclass <int, float> MIF; // use myclass <T1, T2>
Myclass <float, float> MFF; // use myclass <t, t>
Myclass <folat, int> MFI; // use myclass <t, int>
Myclass <int *, float *> MP; // use myclass <t1 *, T2 *>

If multiple local creden match a declaration to the same extent, it is called a declaration with two meanings:

Myclass <int, int> m; // error: Similarly, Chen de matches myclass <t, t> and myclass <t, int>
Myclass <int *, int *> m; // error: Match myclass <t, t> and myclass <t1 *, T2 *> to the same extent.

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.