迭代器 CPP,运算符重载

Iterator cpp, operator overloading

本文关键字:重载 运算符 CPP 迭代器      更新时间:2023-10-16

我为我的输入迭代器编写了一个运算符=,但得到错误,上面写着"错误:成员'operator='的额外限定"

这是一段代码:

input_iterator& input_iterator::operator=(const input_iterator &customerSource){
     if (this == &customerSource){
        return *this;
     }
     innerIter = customerSource.innerIter;
     return *this;
  }

您正在类定义中定义一个成员函数。在这种情况下,不应指定class_name::

替换为此

input_iterator& operator=(const input_iterator &customerSource){
     if (this == &customerSource){
        return *this;
     }
     innerIter = customerSource.innerIter;
     return *this;
  }

或者将函数定义从类中移出。