Operator overloading c++

In C++, why do we have to use the syntax ‘&’ for operator overloading, does it related to address or something? Like this: bool operator<(const <type> &a,const <type> &b). But not this: bool operator<(const <type> a,const <type> b)

1 Like

yes it is passing by reference which means that address is passed. As if you don’t write & then the variable is passed by value which means a new variable is created locally which consumes memory.Think of operators just as special type of functions. for more details check out this link.But the other one will also give correct ans. unless you modify a and b in definition. but consume more memory.

//