The operator in class B hides the operator in class A. This is a problem with any method defined in a derived class that overloads a method in a super class. If name lookup finds a name match in B
it doesn't look in A
, even if the match(s) found in B
can't be called.
You need to bring it into the scope of B:
class X{};
class Y{};
class A {
public:
auto operator[](X) {};
};
class B : public A {
public:
using A::operator[]; // <-- you need this
auto operator[](Y){};
};
int main() {
A a;
B b;
b[X{}]; // OK
b[Y{}]; // OK
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…