outputting an overloaded operator...

I want to output an overloaded insertion operator using a member function inside the same class as the overloaded insertion operator. I really dont know how to do it/syntax. and i cant find an answer in my texts.
anyone have any tips?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  std::ostream& operator<<( std::ostream& out, const Point& p )
{
	out << "Point (" 
		<< p.get_x() 
		<< ", " 
		<< p.get_y() 
		<< ")\n";
	return out;
}

void Point::printShapeInfo()
{
	Point::ostream& operator<<( out, p);
}
Assuming you have correctly defined stream insertion operator and it works.

You can simply do:
1
2
3
4
5
6
7
8
9
void Point::printShapeInfo()
{
	std::cout << *this;
}
//or
void Point::printShapeInfo(std::osream& out)
{
	out << *this;
}
Last edited on
thank you very much, it worked.
Topic archived. No new replies allowed.