Inheritance Problem
Carlo Wood
carlo@alinoe.com
Thu May 10 11:04:00 GMT 2001
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>
More information about the Gcc
mailing list