The difference between c ++ like templates and function templates

1. No automatic type derived class template;

2. class templates can have default parameters in the template parameter list;

#include <the iostream>
 the using  namespace STD; 

Template < class NameType, class AgeType = int >
 class the Person {
 public : 
    NameType name; 
    AgeType Age; 
    the Person (name NameType, AgeType Age) { 
        the this -> name = name;
         the this -> Age = Age; 
    } 
}; 

void Test () {
     // the Person <> P ( "Tom", 22 is); automatic type can not be derived, can specify the type of display 
    the Person < String , int > P ( " Tom " , 22 is); 
    Cout << p.name << "  " << p.age << endl;
     // can declare types in the parameter, you can not specify where the 
    the Person < String > P2 ( " Jack " , 23 ); 
    COUT << p2.name << "  " << p2.age << endl; 
} 

int main () { 
    Test (); 
    System ( " PAUSE " );
     return  0 ; 
}

Guess you like

Origin www.cnblogs.com/xiximayou/p/12106464.html