#include <iostream>
using namespace std;
template<class T>
class Test;
template<class T>
ostream& operator << (ostream& out, const Test<T> &obj);
template <class T>
class Test
{
private:
int num;
public:
Test(int n=0){num=n;}
friend ostream& operator<< <> (ostream& out, const Test<T>&obj);
//注意在<<后加上<>表明这是个函数模板
};
template <class T>
ostream& operator<< (ostream& out , const Test<T>&obj)
{
cout << obj.num;
return out;
}
int main()
{
Test<int> t(2);
cout << t;
return 0;
}
using namespace std;
template<class T>
class Test;
template<class T>
ostream& operator << (ostream& out, const Test<T> &obj);
template <class T>
class Test
{
private:
int num;
public:
Test(int n=0){num=n;}
friend ostream& operator<< <> (ostream& out, const Test<T>&obj);
//注意在<<后加上<>表明这是个函数模板
};
template <class T>
ostream& operator<< (ostream& out , const Test<T>&obj)
{
cout << obj.num;
return out;
}
int main()
{
Test<int> t(2);
cout << t;
return 0;
}