The following code snippet fails to compile:
Код: Выделить всё
struct HasOperatorMinus { int v; HasOperatorMinus operator-(HasOperatorMinus o) { return operator-(this->v, o.v); } }; auto f(HasOperatorMinus a) { return a - a; } Код: Выделить всё
:3:80: error: too many arguments to function call, expected single argument 'o', have 2 arguments 3 | HasOperatorMinus operator-(HasOperatorMinus o) { return operator-(this->v, o.v); } | ~~~~~~~~~ ^~~ :3:22: note: 'operator-' declared here 3 | HasOperatorMinus operator-(HasOperatorMinus o) { return operator-(this->v, o.v); } | ^ ~~~~~~~~~~~~~~~~~~ Код: Выделить всё
operator-(this->v, o.v)Код: Выделить всё
operator-Dear reader, please do not tell us that we can use the "infix" notation in the implementation. The question is about the difference between the prefix notation and the infix.
Источник: https://stackoverflow.com/questions/781 ... ion-failur
Мобильная версия