TITLE: pointer type and access specifiers (Newsgroups: comp.std.c++, 7 Jul 97) SCHEPLER: Daniel Schepler (daniel@frobnitz.wustl.edu) wrote: : class base { : protected: : void foo(int); : }; : : class derived : public base { : private: : base *obj; : public: : void doFoo(int a) { : foo(a); : obj->foo(a); // Access error : } : }; : : It seems that according to the C++ draft standard, the first access in : doFoo is legal because base::foo is also accessible as a protected : member of derived. However, the second access is illegal, since : derived::doFoo is not a member function of base. KUEHL: kuehl@horn.informatik.uni-konstanz.de (Dietmar Kuehl) Not exactly. The second access is illegal because it is unknown whether 'obj' is indeed a 'derived'. ... and it makes a lot sense to deny access in this case: If 'obj' is actually pointing to an object of another class, say 'sibling', also derived from 'base', it would be possible to access 'sibling's state using a 'derived' member function. Since 'sibling' and 'derived' are not really related, access to the protected part of 'sibling', or any other class derived from 'base', by a method of 'derived' is denied. SCHEPLER: : Anyway, I think this type of access should be allowed in this : context. KUEHL: I would definitely be opposed to allow this access, although I once also wanted to have it: It would break encapsulation.