Consider the following code:
struct A {
void operator++() const {}
};
void operator++(const A&) {}
int main () {
const A ca;
++ca; // g++ Error (as expected): ambiguous overload for ‘operator++’
A a;
++a; // g++ Warning: "ISO C++ says that these are ambiguous,
// even though the worst conversion for the first is better
// than the worst conversion for the second"
// candidate 1: void operator++(const A&)
// candidate 2: void A::operator++() const
}
Why is g++ only issuing a warning and not an error on ++a
? In other words, how is the non-member function a better fit than the member function?
Thank you!