标签:his lan ++ define space return warnings 姓名 --
类模板,成员函数类外实现
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
using namespace std;
template<class T1,class T2>
class Person
{
public:
Person(T1 name, T2 age);
// {
// this->m_Name = name;
// this->m_Age = age;
// }
T1 m_Name;
T2 m_Age;
void show();
// {
// cout << " 姓名: " << this->m_Name << " 年龄: " << this->m_Age << endl;
// }
};
//类外实现成员函数
template<class T1,class T2>
Person<T1, T2>::Person(T1 name, T2 age):m_Name(name),m_Age(age){}
template<class T1,class T2>
void Person<T1, T2>::show()
{
cout << " 姓名: " << this->m_Name << " 年龄: " << this->m_Age << endl;
}
int main()
{
Person<string, int> p1("xiaozhao", 27);
p1.show();
return 0;
}
C++(template模板 && 类模板 成员函数类外实现)
标签:his lan ++ define space return warnings 姓名 --
原文地址:https://www.cnblogs.com/lodger47/p/14703960.html