Uncertainty of the call does not occur because the overload through the method is not declared as const . As a result, your overload through the method implements the overload of the binary operator + for parameters
не-const + const
And the overload by a separate function implements the overload of the binary operator + for parameters
const + const
This difference in the constancy of the first argument allows the compiler to avoid ambiguity when choosing a method. for example
int main() { Foo a(0), b(0); a + b; // Вызывается перегрузка методом класса const Foo ca(0), cb(0); ca + cb; // Вызывается перегрузка отдельной функцией }
If you add const your method declaration
Foo operator+(const Foo& f) const { return m_a + f.m_a; }
then both overloads will immediately become fully equivalent and the compiler will start to swear at ambiguity when trying to use the operator.
;afterFoo operator+(const Foo& f);. And what isf1inside a class method? - AnT