In the following code:
struct A{
protected:
virtual void IAmProtected() = 0;
};
struct B: public A{
private:
A * a;
protected:
void IAmProtected() override;
public:
void doSomething(){
a->IAmProtected(); // ERROR: 'IAmProtected' is a protected member of 'A'
}
};
I get 'IAmProtected' is a protected member of 'A' which I find to be strange since B is in fact an extension of A.
I want to know
- Why does this happen?
- How can I prevent this?