How come the following piece of code compiles (and prints V::operator+)?
#include <iostream>
namespace V {
struct B {};
template<typename T>
auto operator+(T rhs) -> T {
std::cout << "V::operator+\n";
return rhs;
}
}
struct A : V::B {};
int main() {
+A();
}
The class A is outside of the namespace V and inherits from B, which is inside V. V also contains an operator template that could, for example, be used on B.
No operator+ is defined for A outside of V, and yet it can be called on A without any qualification (something like V::operator+(A())). Removing the inheritance produces the expected error 'operator+' not defined.
Why can this operator be used outside of V without qualification?