类模板即在关键字template后接上类即为类模板
#include<iostream>
using namespace std;
//类模板
template<class NameType,class AgeType>
//有两个不同的数据类型,string和int
class Person
{
public:
Person(NameType name,AgeType age)
{
this->m_name=name;
this->m_age=age;
}
void showPerson()
{
cout<<"name: "<<this->m_name<<"age: "<<this->m_age<<endl;
}
AgeType m_age;
NameType m_name;
};
void test01()
{
Person<string,int> p1("Tom",99);
p1.showPerson();
}
int main()
{
test01();
return 0;
}