Member function templates cannot be virtual! On the contrary Odinary member function templates can is virtual.
Linkage of Templates
default"C + +void Normal (); No-templates cannot has C linkage"cvoid Invalid ();
Function templates can have internal linkage.
1 // Use keyword static to indicate internal linkage 2 Static void Internal ();
Template Parameters
1. Type parameter
1 // a template with one type parameter and one non-type parameter 2 int class SomeClass;
2. Non-type parameter
A Non-type parameter must has determined value during Compile-time or Link-time. Allowed Are:integer/enumeration; Pointer Reference
1 // actually these-the same, array is converted to a pointer 2 template<int buf[5class SomeClass; 3 template<intclass Somecclass;
3. Template parameter
1 // a function template with a template parameter 2 // class is ok but union and struct am not 3 class C>4void f (c<int> * p);
Interestingly, the parameter of the parameter (which is a template) of the template cannot being used by the (outer) Templat E.
1 class List>2class Node {3 static T * storage; // no! Tis the parameter of the parameter4 5 };
Default parameters
1#include <iostream>2#include <typeinfo>3#include <string>4 5 using namespacestd;6 7 //You can specify default value of T2 only if8 //For the parameters after it9Template<typename T1, TypeName T2, TypeName t3=int>Ten classTriple; One ATemplate<typename T1, TypeName t2=Double, TypeName T3> - classTriple; - theTemplate<typename t1=Char, TypeName T2, TypeName t3> - classTriple; - - //definition +Template<typename T1, TypeName T2, TypeName t3> - classTriple + { A Public: at Triple () - { - T1 T1; - T2 T2; - T3 T3; -cout << typeid (T1). Name () <<Endl; incout << typeid (T2). Name () <<Endl; -cout << typeid (T3). Name () <<Endl; to + } - }; the * intMain () $ {Panax NotoginsengTriple<>Trio; - return 0; the}Actual Parameters for a Template
SUBSTITUTION FAILURE isn't an ERROR
1. Local classes and local enumerations cannot be real type parameters
2. unamed classes and unamed enumerations cannot neither.
Changelog
2015/6/26 Start this page.
C + + Template programming-eighth chapter in-Depth template basics