I've been having some problems trying to implement an overloaded << operator function that can print out a std::list which is a member of one of my classes. The class looks like this:
class NURBScurve {
vector<double> knotVector;
int curveOrder;
list<Point> points;
public:
/* some member functions */
friend ostream& operator<< (ostream& out, const NURBScurve& curve);
};
The key member variable I am interested in is the list of "Points" - this is another class that I have created which stores coordinates of a point along with associated member functions. When I try and implement the overloaded << operator function as:
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;
}
I start to get problems. Specifically, I get the following error: error:
no match for ‘operator=’ in ‘it = curve->NURBScurve::points. std::list<_Tp, _Alloc>::begin [with _Tp = Point, _Alloc = std::allocator<Point>]()’
/usr/include/c++/4.2.1/bits/stl_list.h:113: note: candidates are: std::_List_iterator<Point>& std::_List_iterator<Point>::operator=(const std::_List_iterator<Point>&)
I'm a bit stumped here, but I believe it has something to do with the list iterator I am using. I'm also not too confident with the notation of curve.points.begin().
If anyone can shed some light on the problem I would appreciate it. I'm at the point where I've been staring at the problem for too long!