#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
//模板类
template<class T1, class T2>
class Person
{
//template<T1 name,T2 age>
//类模板 类内实现,如果在类内声明同实现,那么函数就是全局函数
friend void print(Person<T1, T2>& p)
{
cout << p.name << endl;
cout << p.age << endl;
}
public:
Person(T1 name, T2 age)
{
this->name = name;
this->age = age;
}
private:
T1 name;
T2 age;
};
void test()
{
Person<string, int> p1("luxi", 100);
print(p1);
}
int main() {
test();
system("pause");
return 0;
}
06-29
680
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)