structure
is nothing but a class with all its data members and functions defined in public
scope. So you can implement any operators which is valid for a class
.
If your question is on operator overloading, all overloaded operators can be defined for a class
is valid for a structure
.
You can refer this Operator overloading question and answer to understand more on operator overloading
POINT(int x = 0, int y = 0) : x(x), y(y) {} //(3rd line)
bool operator ==(POINT& a) {return a.x==x && a.y==y;}//(4th line)
3rd line is a constructor
, and 4th line is an operator overloading function for operator ==
.
POINT p1(2,3); // 3rd line will get called and update x=2 and y=3
POINT p2; // 3rd line will get called and consider x=0 and y=0
//since function definitiion is defaulted with value x=0 and y=0;
if(p2==p1) {....}
// 4th line will get called and compare P1 and P2