类模板成员函数类外实现
class Person {
public:
Person(T1 name, T2 age);
void showPerson() {
cout << "name: " << this->m_Name << " age: " << this->m_Age << endl;
}
T1 m_Name;
T2 m_Age;
};
template <class T1, class T2>
Person<T1,T2>::Person(T1 name, T2 age) {//<表示Person类模板的实现>
this->m_Age = age;
this->m_Name = name;
}
template <class T1, class T2>
void Person<T1,T2>::showPerson(){
//实现
}
在类内只声明,不实现,在外部实现需要加模板和模板的作用域