Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Nested clas...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 8 Topic 9586 of 9828
Post > Topic >>

Re: Nested class accessing private member of parent

by Bart van Ingen Schenau <bart@[EMAIL PROTECTED] > May 10, 2008 at 02:08 PM

Pavel Minaev wrote:

> On 10 ???, 07:26, sat_a...@[EMAIL PROTECTED]
 wrote:
>> In the following  code, nested class B is accessing private member of
>> A. Is this allowed? This code compiles on Comeau online test compiler
>> and Visual Studio 2005.
>>
>> class A
>>
>> {
>>     class B
>>    {
>>        A* a;
>>        int bVal;
>>        B() { bVal = a->aVal; } // This compiles
>>     };
>>
>> private:
>>
>>     int aVal;
>>
>> };
> 
> No, this is not allowed. I can't say anything about Comeau, but it is
> a well-known extension in Visual C++. To be standard-compliant, you
> need an explicit friend declaration for the innter class in the outer
> class.

Actually, it used to be not allowed, but the standard got changed such
that nested cl***** (and their members) have the same access rights as
the members of the outer class. See Core Language issues 45 and 494
(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html)

The two compilers might already implement the new behaviour.

Bart v Ingen Schenau
-- 
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.para****ft.com/c++-faq-lite/

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
Nested class accessing private member of parent
sat_andi@[EMAIL PROTECTED  2008-05-09 21:26:07 
Re: Nested class accessing private member of parent
Pavel Minaev <int19h@[  2008-05-10 06:14:29 
Re: Nested class accessing private member of parent
marlow.andrew@[EMAIL PROT  2008-05-10 14:07:54 
Re: Nested class accessing private member of parent
David Pol <david@[EMAI  2008-05-10 14:08:31 
Re: Nested class accessing private member of parent
Bart van Ingen Schenau &l  2008-05-10 14:08:09 
Re: Nested class accessing private member of parent
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-10 14:13:29 
Re: Nested class accessing private member of parent
Pete Becker <pete@[EMA  2008-05-11 16:40:25 
Re: Nested class accessing private member of parent
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-12 09:28:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:02:09 CDT 2008.