brand_guy 2022-06-30 20:15 采纳率: 57.1%
浏览 32
已结题

关于#运算符#的问题,如何解决?

在定义的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'以及下面还有几百个看不懂的报错提示,但是只看重载运算符<<部分的代码,又没找出问题
  • 写回答

2条回答 默认 最新

  • 真相重于对错 2022-07-01 07:37
    关注
    
    void display(ostream& os=cout);
    改成
    void display(ostream& os=cout)const;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月9日
  • 已采纳回答 7月1日
  • 创建了问题 6月30日

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持