C++STL_类模板举例
1 #include<stdio.h> 2 #include<typeinfo.h> 3 4 template <class T1,class T2> 5 class A{ 6 T1 i; 7 T2 j; 8 public: 9 A(T1 t1,T2 t2){i=t1;j=t2;} 10 bool comp(){return i>j;} 11 void print_Type(); 12 }; 13 template <class T1,class T2> 14 void A<T1,T2>::print_Type() 15 { 16 printf("i的类型是%s\n",typeid(i).name()); 17 printf("j的类型是%s\n",typeid(j).name()); 18 } 19 int main(void) 20 { 21 A<int,double> a(3,67.8); 22 if(a.comp()) 23 printf("i>j\n"); 24 else printf("i<=j\n"); 25 a.print_Type(); 26 return 0; 27 }
不要让今天成为明天的遗憾!