//============================================================================
// Name : templatefriend.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
template <class T> //前向声明
class Test;
template <class T>
ostream & operator<<(ostream &out,const Test<T> &obj);
template <class T>
Test<T> operator+(const Test<T> &obj,const Test<T> &obj1);
template <class T>
class Test
{
public:
Test(int n=0){num = n;}
Test(const Test<T>©) {num = copy.num;}
friend ostream & operator << <>(ostream &out, const Test<T>&obj);
friend Test<T> operator+ <>(const Test<T> &obj,const Test<T> &obj1);
private:
int num;
};
template <class T>
ostream& operator<<(ostream & out, const Test<T>&obj)
{
out<<obj.num;
return out;
}
template <class T>
Test<T> operator+(const Test<T> &obj,const Test<T> &obj1)
{
Test<T> temp;
temp = obj.num + obj1.num;
return temp;
}
int main()
{
Test<int> t(2);
cout<<t;
return 0;
}