template<typename Type> class MyClass {
private:
Type a;
public:
MyClass(Type org):a(org){
}
void print(){
cout<<a<<endl;
}
}
int main()
{
int index=4;
MyClass<int> obj(index);
obj.print();
return 0;
}
template<typename Type> class MyClass声明了一个类模板,
模板类是类模板的特化,MyClass<int>实例化了类模板,即将Type 实例为int 类型,这样我们就得到了一个模板类。