[013] template-non-type template parameters

Source: Internet
Author: User

In the template, apart from defining type parameters, we can also define non-type parameters. For example:

Temlate <unsigned N, unsigned m> int Foo (const char (& P1) [N], const char (& p2) [m]) {return strcmp (P1, p2 );}

Note that the compiler inserts an empty character at the end of a string literal constant as the final character.

For example, we call

Foo ("hi", "mom ");

In fact, the compiler will instantiate the following versions:

Int Foo (const char (P1) [3], const char (P2) [4]);

-----------

Conclusion: In the template definition, the non-type parameter of the template is a constant value. Where constant expressions are required, you can use non-type parameters, such as the size of the specified array.

[013] template-non-type template parameters

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.