次のクラス階層があるとします。
class Base
{
protected:
virtual void foo() = 0;
friend class Other;
};
class Derived : public Base
{
protected:
void foo() { /* Some implementation */ };
};
class Other
{
public:
void bar()
{
Derived* a = new Derived();
a->foo(); // Compiler error: foo() is protected within this context
};
};
私もそれを変更できると思いますa->Base::foo()
がfoo()
、クラスでは純粋に仮想であるBase
ため、呼び出しはDerived::foo()
とにかく呼び出しになります。
ただし、コンパイラはを拒否しているようa->foo()
です。論理的だと思いますが、その理由がよくわかりません。私は何かが足りないのですか?この特殊なケースを処理することはできません(すべきではありません)?
ありがとうございました。