This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Inheritance Problem


On Thu, May 10, 2001 at 11:17:38AM -0400, Brian Osman wrote:
> That was my initial reaction, but I'm not so sure. Look at 11.5 in the
> standard. From my quick reading, it sounds like Carlo (and thus, the
> compiler) is correct.
> 
> -Brian

Well, I agree that a class B has access to the same members in
any B* object as it does to what 'this' is pointing to.
I suppose I formulated it wrong.  Its just that access to
protected members of another A* even if class A is a base
class, is not allowed.

When I said that probably access this->i would fail, I made a
mistake; I MEANT to say that the following would fail:

class A {
protected:
  int i;
};
 
class B : public A {
private:
  int j;
public:
  void foo(void)
  {
    A* ap = this;
    j = ap->i;		// No access
  }
};

Accessing this->i will succeed because accessing members in ANY
class B will succeed (including protected member in base class A).

-- 
Carlo Wood <carlo@alinoe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]