The protected members form the special class interface for the member functions of the derived type. This is different from the public interface, which is formed by non-member functions in the same namespace and public members, and one of the differences is that protected members are *not* accessible through abstractDMA itself; only through classes that are derived from it.
Compare:
1 2 3 4 5 6 7 8 9 10 11 12 13
struct Base {
protected:
int i;
};
struct Derived : Base {
void f(Base& b, Derived& d)
{
++b.i; // error
++d.i; // okay
++i; // okay
}
};
clang++ says:
test.cc:9:13: error: 'i' is a protected member of 'Base'
++b.i; // error
^
test.cc:3:9: note: can only access this member on an object of type 'Derived'
int i;
^
well, member functions and friends of abstractDMA itself can access them, but once you step outside of abstractDMA, you need to be handling an object of a derived type.
well, member functions and friends of abstractDMA itself can access them, but once you step outside of abstractDMA, you need to be handling an object of a derived type.
Who the ____ decided that that should be so? Why not either always have access to protected members or never have access to them?
Guessing some technical reason that's beyond me but this just seems confusing and illogical.
I think it's too permissive actually, I'd only allow access from the same class and through the current object in the derived class (that is, I'd reject line 10 in my example), but of course member access doesn't know object identities, it's decided on types alone.