I have a Point2D class
Point2D
class Point2D
{
public:
int getX() const;
int getY() const;
void setX(int);
void setY(int);
protected:
int x;
int y;
};
I am trying to overload the output operator << to work with Point2D iterator p2d_list.begin() but i am unsure how to do it , this is my attempt
ostream& operator<< (ostream& afile, Point2D* p2)
{
afile<<left
<<setw(1)
<<"["
<<left
<<setw(5)
<<p2->getX()
<<" ,"
<<left
<<setw(5)
<<p2->getY()
<<" ] "
<<left
<<setw(6)
<<p2->getScalarValue()
<<endl;
return afile;
}
In my main function
int main()
{
list<Point2D> p2d_list;
list<Point2D>::iterator p2 = p2d_list.begin();
while ( p2 != p2d_list.end() )
{
cout<<p2; //error here
p2++;
}
}
I am getting the following Error
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_List_iterator<_Mylist>' (or there is no acceptable conversion)
How do i overload the output operator << so that it works with Point2D iterator **p2d_list.begin()