我在尝试实现一个重载的<<运算符函数时遇到了一些问题,该函数可以打印出一个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)