Tell me in two words what Dattle wanted to say, but I don’t get it:

Operations as an element-function and as global functions

Regardless of whether a function-operation is declared as an element-function or as a global function, the operation is used in the same way in the expression. So which option is better?

When an operation function is implemented as an element, the left (or only) operand must be an object (or a reference to an object) belonging to the class of this operation. If it is necessary that the left operand be an object of another class or an object of the main type, this function-operation should be declared as a function that is not a member of the class (as we will do in section 11.5, where “and” are overloaded as transmission and retrieval operations from the stream) . A global function-operation can be made different if it should have direct access to private or protected elements of a class.

Operation functions that are elements of a certain class are called (implicitly by the compiler) only when the left operand of a two-place operation is an object of this particular class, or when the only operand of a one-place operation is an object of this class.

screen from book

    1 answer 1

    If you overload the operator, say, + for class X, it can be defined in two ways - by a separate function

    X operator+(const X& l, const X& r); 

    or as a member of class X

     X operator+(const X& r); 

    In the first case, if the class X can be created from an integer by implicit conversion, operations like

     1+x 

    where x is an object of class X. In the second case, the object of the class must always come first.