类模板外部实现
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
template<class T>
class Person
{
template<class T>
friend ostream& operator<<(ostream& os, Person<T>& p);
public:
Person(T age ,T id);
void show();
public:
T age;
T id;
private:
};
template<class T>
Person<T>::Person(T age, T id)
{
this->age = age;
this->id = id;
}
template<class T>
void Person<T>::show()
{
cout << "Age:" << age <<endl<< "Id:" << id << endl;
}
template<class T>
ostream& operator<<(ostream& os, Person<T>& p)
{
os << "Age:" << p.age << endl << "Id:" << p.id << endl;
return os;
}
int main()
{
Person<int> p(10, 20);
cout << p;
system("pause");
}