在定义的class中重载运算符<<报错,而样例中用同样的格式重载,却没有问题。
#ifndef A
#ifndef A
#define A
#include<fstream>
#include<vector>
#include<iostream>
#include<algorithm>
#include"Pell_iterator.h"
using namespace std;
class Pell{
friend class Pell_iterator;
friend ostream& operator<<(ostream& os,const Pell& rhs );
public:
Pell(int bp=1,int len=1);
int size()const{return _length;};//返回对象序列的长度
int beg_pos()const{return _beg_pos;};//返回对象的开始位置
void change(int bp=1,int len=1);//重新设置对象
bool next(int& val)const;//将要操作的下一数字赋给val,同时“光标”后移一位
void next_reset()const{_next=_beg_pos-1;};//重置将要操作的下一数字至开始位置
int elem(int pos)const;//返回对象序列中第pos个数字
int sum()const;//求对象序列的和
bool is_elem(int val);//判断val数值是否包含在对象的序列中
void display(ostream& os=cout);//用于输出对象包含的序列
static void generate();//用于填充数列
Pell& copy(const Pell);
typedef Pell_iterator iterator;
iterator begin()const
{
iterator it(_beg_pos);
return it;
}
iterator end()const
{
iterator it(_beg_pos+_length);
return it;
}
private:
static const int _max_size=40;
int _length;
int _beg_pos;
mutable int _next;
static vector<int> _elems;
};
ostream&
operator<<(ostream& os,const Pell& rhs )
{
cout<<'('<<rhs._beg_pos<<','<<rhs._length <<") ";
rhs.display(os);
return os;
}
#endif
#include"Pell.h"
#include<iostream>
using namespace std;
int main()
{
Pell it(4,3);
cout<<it;
return 0;
}
报错no match for 'operator'以及下面还有几百个看不懂的报错提示,但是只看重载运算符<<部分的代码,又没找出问题