template友元的写法

来源:互联网 发布:json 遍历取值 编辑:程序博客网 时间:2024/04/28 21:29

#include<iostream>
using namespace std;

template<class T>
class test;

template<class T>
ostream& operator<<(ostream& os,const test<T>& src);

template<class T>
class test
{
T m;
public:
test(T i):m(i){}
friend ostream& operator<<<>(ostream& os,const test<T>& src);
};


template<class T>
ostream& operator<< (ostream& os,const test<T>& src)
{
os<<"operator<<"<<src.m;
return os;
}

int main()
{
test<int> x(10);
cout<<x<<endl;
return 0;
}


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/akirya/archive/2008/06/04/2509791.aspx

原创粉丝点击