CPP templates: Non-type template parameter restrictions

Source: Internet
Author: User
Non-type template parameters are limited. Generally, they can use a constant INTEGER (including enumeration values) or a pointer to an external linked object.

Floating Point Numbers and class objects cannot be used as non-type template parameters:

Template <double VAT> // Error
Double process (Double V)
{
Return v * VAT;
};

Template <STD: string name> // Error
Class myclass {
......
};

Because the string text is an internal connection object, it cannot be used as a template argument.

Template <char const * Name>
Class myclass {
};

Myclass <"hello"> X; // error: String text "hello" is not allowed"

In addition, global pointers cannot be used as template parameters.
-------------- The following is for your reference -------------------
External link:
InCodeDeclared out-of-block or modified using extern const
Scope: ThisProgram.

Internal link:
Static or const modified
Scope: this file.

No link:
Automatic variables, register variables, declared in the code block using static.
Scope: code block.

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.