类模板的是为了解决这么一类问题存在的:当代码里面需要定义多个类似的类,而这些类中只有基本数据格式不一样或某个类参数不一样。类模板可以提高代码的简洁性。下面是随意的三个模板:
  模板一:
template <class numtype>
class compare
{
public:
compare(numtype a,numtype b){
x = a;
y = b;
}
numtype max(){
return (x>y)?x:y ;
}
numtype min(){
return (x<y)?x:y ;
}
private:
numtype x;
numtype y;
};
  模板二:
template <class A, class B>
class outmy{
public:
outmy(A a,B b){
x = a;
y = b;
}
public:
A Big(){
cout<<"Big = "<<x<<endl;
return x;
}
B Comfux(){
cout<<"Comfux = "<<y<< endl;
return y;
}
private:
A x;
B y;
};