语法:
    template<模板参数列表>
    返回类型 类名<模板参数列表>::函数名(形参列表)

    总结:类模板中成员函数类外实现时,需要加上模板参数列表

    1. template<class T1,class T2>
    2. class Person
    3. {
    4. public:
    5. Person(T1 name, T2 age);
    6. //{
    7. // this->m_Name = name;
    8. // this->m_Age = age;
    9. //}
    10. void showPerson();
    11. //{
    12. // cout << "姓名:" << this->m_Name << " 年龄:" << this->m_Age << endl;
    13. //}
    14. T1 m_Name;
    15. T2 m_Age;
    16. };
    17. //构造函数类外实现
    18. template<class T1,class T2>
    19. Person<T1, T2>::Person(T1 name, T2 age)
    20. {
    21. this->m_Name = name;
    22. this->m_Age = age;
    23. }
    24. //成员函数类外实现
    25. template<class T1, class T2>
    26. void Person<T1, T2>::showPerson()
    27. {
    28. cout << "姓名:" << this->m_Name << " 年龄:" << this->m_Age << endl;
    29. }
    30. void test01()
    31. {
    32. Person<string, int> P("Tom", 20);
    33. P.showPerson();
    34. }
    35. int main(void)
    36. {
    37. test01();
    38. system("pause");
    39. return 0;
    40. }