Nested class accessing private member of parent
  Home FAQ Contact Sign in
comp.lang.c++.moderated only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c++.moderated Profile…
 Up
Nested class accessing private member of parent         


Author: sat_andi
Date: May 9, 2008 19:31

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;
};

int main(int argc, char** argv) {}

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
7 Comments
Re: Nested class accessing private member of parent         


Author: Pavel Minaev
Date: May 10, 2008 04:20

On 10 ???, 07:26, sat_a...@yahoo.co.uk 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;
>
> }; ...
Show full article (0.75Kb)
no comments
Re: Nested class accessing private member of parent         


Author: marlow.andrew
Date: May 10, 2008 13:07

On 10 May, 05:14, Pavel Minaev gmail.com> wrote:
> On 10 ???, 07:26, sat_a...@yahoo.co.uk 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: ...
Show full article (1.07Kb)
no comments
Re: Nested class accessing private member of parent         


Author: David Pol
Date: May 10, 2008 13:08

On 10 mayo, 05:26, sat_a...@yahoo.co.uk 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;
>
> }; ...
Show full article (1.36Kb)
no comments
Re: Nested class accessing private member of parent         


Author: Bart van Ingen Schenau
Date: May 10, 2008 13:08

Pavel Minaev wrote:
Show full article (1.30Kb)
no comments
Re: Nested class accessing private member of parent         


Author: Daniel Krügler
Date: May 10, 2008 13:13

On 10 Mai, 14:14, Pavel Minaev gmail.com> wrote:
> On 10 ???, 07:26, sat_a...@yahoo.co.uk 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: ...
Show full article (2.14Kb)
no comments
Re: Nested class accessing private member of parent         


Author: Pete Becker
Date: May 11, 2008 14:55

On 2008-05-10 10:07:54 -0400, marlow.andrew@googlemail.com said:
>
> Er, that doesn't sound like an extension to me. It sounds like a bug.
> Allowing stuff to compile that shouldn't compile an' all that. Unless,
> of course, it is documented in which case it's a feature.
>

Note that the C++ standard does not have a notion of "shouldn't
compile". The requirement is that for ill-formed code the compiler must
issue a diagnostic. Once it's done that, the standard does not impose
any requirements. That's the standard's mechanism for conforming
extensions: issue a diagnostic, then do whatever your extension is.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
no comments
Re: Nested class accessing private member of parent         


Author: Daniel Krügler
Date: May 12, 2008 08:28

On 12 Mai, 00:40, Pete Becker versatilecoding.com> wrote:
> On 2008-05-10 10:07:54 -0400, marlow.and...@googlemail.com said:
>> Er, that doesn't sound like an extension to me. It sounds like a bug.
>> Allowing stuff to compile that shouldn't compile an' all that. Unless,
>> of course, it is documented in which case it's a feature.
>
> Note that the C++ standard does not have a notion of "shouldn't
> compile". The requirement is that for ill-formed code the compiler must
> issue a diagnostic. Once it's done that, the standard does not impose
> any requirements. That's the standard's mechanism for conforming
> extensions: issue a diagnostic, then do whatever your extension is.

As I read the definition of "ill-formed" (as the negation of
well-formed), not all ill-formed programs need to (or can) be
diagnosed. This is so, because well-formedness also requires
fulfillment of the One Definition Rule, and not all parts of
the ODR need to be diagnosed (e.g. duplicate, but not "equivalent"
definitions of an entity in different translation units).

Greetings from Bremen,

Daniel Krügler
Show full article (1.24Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: Access XP can create Access 2000 MDE ?microsoft.public.access ·
How do I 'back migrate' an Access database from Access 2007 to 200microsoft.public.access ·