1 #include <iostream>
2 #include <string>
3 #include<fstream>
4 using namespace std;
5
6 template<class T1,class T2>
7 class Person
8 {
9 public:
10 //函数声名
11 Person(T1 name, T2 age);
12 //{
13 // this->m_Name = name;
14 // this->m_Age = age;
15 //}
16 void showPerson();
17 //{
18 // cout << "姓名: " << this->m_Name << " 年龄:" << this->m_Age << endl;
19
20 //}
21 T1 m_Name;
22 T2 m_Age;
23 };
24
25 //构造函数类外实现
26 template<class T1,class T2>
27 Person<T1,T2>::Person(T1 name, T2 age)
28 {
29
30 this->m_Name = name;
31 this->m_Age = age;
32
33 }
34
35 //成员函数的类外实现
36 template<class T1, class T2>
37 void Person<T1, T2>::showPerson()
38 {
39 cout << "姓名: " << this->m_Name << " 年龄:" << this->m_Age << endl;
40 }
41
42 void test01()
43 {
44 Person <string, int>p("TOM", 20);
45 p.showPerson();
46 }
47
48 int main()
49 {
50 test01();
51
52
53
54 system("pause");
55
56 return 0;
57
58 }