C++ Protected Class Members are Private???

Nathan Sidwell nathan@codesourcery.com
Thu Feb 20 10:34:00 GMT 2003


Mongryong wrote:
> On Wed, 2003-02-19 at 15:54, Neil Booth wrote:
> 
>>Mongryong wrote:-
>>
>>
>>>    // now, this generates a compiler error!!!
>>>    // right->left: left is protected and can't be accessed??
>>>    left = right->left;
>>
>>left = this->left is OK, but not right->left because it's a different
>>object.  At least, that's my understanding.  Welcome to C++.
>>
> 
> This has got to be a compiler issue.  The compiler knows the context and
> scope from which 'right->left' is called and should be able to determine
> that it's 'okay'.  It's kind of dumb for C++ to define this behaviour as
> not okay.
As Neil says, it is the language. To access protected members of a base
you have to go through the this pointer (this is *harder* to implement
than the semantics you expected.) To see this from the std you need both [11.2]/4
[11.5]/1

No, I don't know the rationale for it.

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org




More information about the Gcc mailing list