Look, it's very simple.
You've defined a struct representing a point. Assuming you have two such structs, the code in question defines a comparison operator for them, so that you can write something like
if (pt1 < pt2) { ...
How can the compiler treat the <
sign? In C++ it's doing the following: the expression pt1 < pt2
gets interpreted as pt1.operator < (pt2)
. That is, the method with special name operator <
of object pt1
is called, with argument equal to pt2
.
Let's see what it is doing. const Point &p
in its argument denotes the other operand being compared. const
says that we are not going to modify the operand (this allows the compiler to produce more effective code), and &
means that we are not copying the struct
passed, but working with actual Point
instance (this is faster again, as no copying is done for the comparison).
Now, the expression x<p.x
checks whether the x
value at the left-hand operand (it's the this
object, that is, the object in context of which the method is running)* against the x
of the right-hand operand. Next, the code checks the case when the left-hand x
is equal to the right-hand one, so the y
's are compared.
*For language purists: the wording is not precise, but for the beginner-oriented explanation it should be ok.