小编Rob*_*son的帖子

重载<<运算符以打印出std :: list

我在尝试实现一个重载的<<运算符函数时遇到了一些问题,该函数可以打印出一个std :: list,它是我的一个类的成员.这个类看起来像这样:

class NURBScurve {
  vector<double> knotVector;
  int curveOrder;
  list<Point> points;
public:
  /* some member functions */
  friend ostream& operator<< (ostream& out, const NURBScurve& curve);
};
Run Code Online (Sandbox Code Playgroud)

我感兴趣的关键成员变量是"点"列表 - 这是我创建的另一个类,它存储点的坐标以及相关的成员函数.当我尝试将重载的<< operator函数实现为:

ostream& operator<<( ostream &out, const NURBScurve &curve)
{
 out << "Control points: " << endl;
 list<Point>::iterator it;
 for (it = curve.points.begin(); it != curve.points.end(); it++)
    out << *it; 
 out << endl;
 return out;
}
Run Code Online (Sandbox Code Playgroud)

我开始遇到问题.具体来说,我收到以下错误:错误:

no match for ‘operator=’ in ‘it = curve->NURBScurve::points. std::list<_Tp, _Alloc>::begin [with _Tp = Point, …
Run Code Online (Sandbox Code Playgroud)

c++ iterator list std

2
推荐指数
2
解决办法
1592
查看次数

标签 统计

c++ ×1

iterator ×1

list ×1

std ×1