+ 1

Operator Overloading<<

https://code.sololearn.com/ca23a1a23A25 how can I fix this error?

7th May 2021, 11:50 AM
Ramisa Fariha
Ramisa Fariha - avatar
3 Answers
+ 1
#include <iostream> using namespace std; class Point { friend ostream& operator<<(ostream&,const Point&); private: float x,y,z; public: Point(float x1=0, float y1=0, float z1=0) { x=x1; y=y1; z=z1; } }; ostream& operator<<(ostream& ostr,const Point& point) { return ostr<< "(" << point.x<< "," << point.y << "," << point.z << ")"; } int main() { Point p1(1,-20,3); cout<<p1; }
7th May 2021, 11:54 AM
YUGRAJ
+ 1
You just need to use point.x , point.y, point.z
7th May 2021, 11:54 AM
YUGRAJ
0
Yes thank you @Yugraj I've corrected it
7th May 2021, 12:08 PM
Ramisa Fariha
Ramisa Fariha - avatar