[over.unary]/2
The unary and binary forms of the same operator are considered to have the same name. [ Note: Consequently, a unary operator can hide a binary operator from an enclosing scope, and vice versa. —end note ]
I'd like to see a compiling example of a snippet where this hiding occurs.
A fairly simple example1:
struct foo {
void operator+(foo const&) {}
};
struct bar : foo {
void operator+() {}
};
int main() {
bar a, b;
a + b; // Can't add two bars
}
The name of the member function is operator+
, so the one declared in bar
hides the one in foo
when we overload it. That makes the addition at the end of main
ill-formed.
But if you had two foo
objects (that are not bar
), the addition would be perfectly okay.
1 - Pardon me it's a non-compiling one, but usually the issue with name hiding is that it prevents programs from building all of a sudden.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With