64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
namespace Listsavitch
{
template<class ItemType>
class List
{
public:
List(int max);
~List();
int length()const;
void add(ItemType new_item);
bool full()const;
void erase();
friend ostream& operator <<(ostream& outs,const List<ItemType>& the_list);//这里出错
private:
ItemType *item;
int max_length;
int current_length;
};
}
template<class ItemType>
ostream& operator <<(ostream& outs,const List<ItemType>& the_list)
{
for(int i=0;i<the_list.current_length;i++)
outs<<the_list.item[i]<<endl;
return outs;
}
#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;
}
template<typename IType>
friend ostream& operator << (ostream& outs,const List<IType>& the_list);//这里出错
//如果是非绑定友元,要这样