#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
template<class T1, class T2>
class Person
{
T1 name;
T2 age;
public:
Person(T1 _name, T2 _age)
{
name = _name;
age = _age;
}
void Show()
{
cout << "name : " << name << " age : " << age << endl;
}
};
//指定传入类型
void PrintPerson1(Person<string, int>& p)
{
p.Show();
}
//参数模板化
template<class T1, class T2>
void PrintPerson2(Person<T1, T2>& p)
{
//查看T1, T2类型
cout << "T1 : " << typeid(T1).name() << endl;
cout << "T2 : " << typeid(T2).name() << endl;
p.Show();
}
//整个类模板化
template<class T>
void PrintPerson3(T& p)
{
//查看T类型
cout << "T : " << typeid(T).name() << endl;
p.Show();
}
void test01()
{
Person<string, int>p("张三", 20);
//PrintPerson1(p);
//PrintPerson2(p);
PrintPerson3(p);
}
int main()
{
test01();
return 0;
}