Usage tips of template keywords in CPP templates

Source: Internet
Author: User
Tips for using template keywords

Note:

The delimiters include:,.,->

1. When the type name has the following properties, you should add the template prefix before the name:
1. the name appears in a template.
2. The name is restricted.
3. The name is not used to specify the list of base class inheritance, nor is it located in the initialization list of the member introducing the constructor.
4. The name depends on the template.

In addition, the prefix template can be used only when the three conditions on the current side are met at the same time. For example:

Template <typename T>

Struct s: x <t>: Base {
S (): x <t >:: base (typename x <t >:: base (0 )){}
X <t> F () {// The template cannot be used.
Template x <t>: C * P; // Statement of pointer P
X <t>: D * q; // Product
}
Typename x <int>: C * s; // optional because it does not comply with Article 4
};

Struct u {
X <int>: C * PC; // The template cannot be used because it is not used in the template, and U is not the template.
};

2. If a Template Name is a dependent name, you need to insert the template keyword before the name

For example:

template
class weird {
Public:
void casel (template shell :: template in :: template deep * P) {

}< BR >}

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.