|
|
Up |
|
|
  |
Author: sat_andisat_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) {}
|
| |
|
| | 7 Comments |
|
  |
Author: Pavel MinaevPavel Minaev Date: May 10, 2008 04:20
> 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 |
|
  |
Author: marlow.andrewmarlow.andrew Date: May 10, 2008 13:07
On 10 May, 05:14, Pavel Minaev gmail.com> 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 |
|
  |
Author: David PolDavid Pol Date: May 10, 2008 13:08
> 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 |
|
  |
|
|
  |
Author: Daniel KrüglerDaniel Krügler Date: May 10, 2008 13:13
On 10 Mai, 14:14, Pavel Minaev gmail.com> 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 |
|
  |
Author: Pete BeckerPete Becker Date: May 11, 2008 14:55
>
> 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 |
|
  |
|
|
  |
Author: Daniel KrüglerDaniel Krügler Date: May 12, 2008 08:28
On 12 Mai, 00:40, Pete Becker versatilecoding.com> wrote:
>> 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 |
  |
|
|
|