#include
using namespace std;
template
class Person {
public:
Person(T1 name, T2 age);
void showPerson();
T1 m_Name;
T2 m_Age;
};
//模板-构造函数类外实现
template
//错误代码:E0135:类模板person没有成员Person
//错误原因:未在类内做出函数声明
Person::Person(T1 name, T2 age) {
this->m_Name = name;
this->m_Age = age;
}
//模板-成员函数类外实现
//即使该成员函数未用到T,也必须加上模板相关
template
void Person::showPerson() {
cout << "姓名: " << this->m_Name << endl << "姓名: " << this->m_Age << endl;
}
void test01() {
PersonP("周公瑾", 20);
P.showPerson();
}
int main() {
test01();
}