Templates of CPP templates explicit and special skills

Source: Internet
Author: User
Note for explicit and special template:

I,
The specified template parameter list must be one-to-one. For example
A non-type value to replace a template parameter. However, if the template parameters have the default template parameters

Template parameters are optional:

Template <typename T>
Class types {
Public:
Typedef int I;
};

Template <typename T, typename u = typename types <t >:: I>
Class S;

Template <>
Class S <void> // OK
{
Public:
Void F ();
};

Template <>
Class S <char, char>; // OK

Template <>

Template <> class S <char, 0>; // error. You cannot use 0 to replace U.

Ii. Global Membership Specialization

# Include <iostream>

Using namespace STD;

Template <typename T>
Class outer {/1
Public:
Template <typename u>
Class inner
{
PRIVATE:
Static int count;
};
Static int code; // 4
Void print () const // 5
{
STD: cout <"generic" <Endl;
}
}
/* Code at 4 and print () at 5. Both common members have a peripheral class template. Therefore,
* Template <> prefix Description: A template real parameter set will be used later to globally optimize the template.
*/
Template <>
Int outer <void >:: code = 12;

Template <>
Void outer <void>: Print () const
{
STD: cout <"outer <void>" <Endl;
}
/* 1. the above definitions will be used to replace the generic definitions of class Outer <void> at 4 and 5; but the class Outer <void>
* Other members still default the template where the property is located at 1 by default.
* 2. After the preceding statement is provided, the outer <void> display feature cannot be provided again.
*/

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.