Pointer to base class method with protected inheritance

Why is this not possible, when I have used using and I can call operator directly?

The using declaration gives you access to the name operator[]. But it doesn't alter the member's type. It stays int &(Foo::*)(size_t). Note the Foo.

So converting to the declared type of o requires a conversion down the inheritance tree. This conversion must check that the target class is indeed derived from the base, but that is an inaccessible base.

One way to work around it is to give Bar a member function that returns that pointer. Inside Bar's scope the base will be accessible to the conversion. Also, this sort of conversion requires a static_cast.


This conversion is not allowed once the base class Foo is inaccessible.

Instead of using using Foo::operator[], maybe this can solve your problem:

int& operator[](size_t index) { // now a Bar::operator[], not Foo:: anymore
    return Foo::operator[](index);
}