template模板后面加类,此类成为类模板。
#include<iostream>
using namespace std;
template<class NameType, class AgeType>
class Person
{
public:
NameType m_Name;
AgeType m_Age;
Person(NameType name, AgeType age)
{
m_Name = name;
m_Age = age;
}
void ShowPerson()
{
cout << "name: " << m_Name << " age: " << m_Age;
}
};
int main() {
Person<string, int> p1("坤坤", 18);
p1.ShowPerson();
}