关于ostream的使用

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:34:25
template<class T>
class Array
{
public:
......
//下面这行是第37行
friend ostream& operator<< (ostream&, const Array<T>&);
...
private:
...
};

这个语句无法通过dev c++4.9.9.2以及visual c++ 6.0的编译,
visual cpp的错误为
f:\cpp study\linklisttemplate\linklisttemplate.hpp(31) : error C2143: syntax error : missing ';' before '&'
f:\cpp study\linklisttemplate\linklisttemplate.hpp(37) : see reference to class template instantiation 'PartsList<T>' being compiled
f:\cpp study\linklisttemplate\linklisttemplate.hpp(31) : error C2433: 'ostream' : 'friend' not permitted on data declarations
f:\cpp study\linklisttemplate\linklisttemplate.hpp(37) : see reference to class template instantiation 'PartsList<T>' being compiled
f:\cpp study\linklisttemplate\linklisttemplate.hpp(31) : err

#include <iostream>
#include <vector>
using namespace std;

template<typename T> class mm
{
public:
friend ostream& operator<<(ostream&,const vector<T>&);
};
这样写有一个警告但通过。应该和你想的原理一样吧,最好把代码贴出来看一下。

把代码贴出来吧