access rules and nested classes

Discussion in 'C++' started by John Harrison, Sep 5, 2003.

  1. The following example (adapted from standard, section 11.8.1)

    class E
    {
    int x;
    class I
    {
    void f(E* p, int i)
    {
    p->x = i; // error
    }
    };
    };

    is illegal because nested class I has no special access to enclosing class
    E. E::x is private and therefore p->x is an access error.

    Yet Comeau C++, gcc 3.2 and Visual C++ 7.1 all compile it. What is going on?
    Has the standard changed recently?

    john
     
    John Harrison, Sep 5, 2003
    #1
    1. Advertising

  2. It is a bug in these compilers. HP's aCC compiler gives the expected error.
    The other vendors are being milder.

    "John Harrison" <> wrote in message
    news:bj99kn$gap5a$-berlin.de...
    > The following example (adapted from standard, section 11.8.1)
    >
    > class E
    > {
    > int x;
    > class I
    > {
    > void f(E* p, int i)
    > {
    > p->x = i; // error
    > }
    > };
    > };
    >
    > is illegal because nested class I has no special access to enclosing class
    > E. E::x is private and therefore p->x is an access error.
    >
    > Yet Comeau C++, gcc 3.2 and Visual C++ 7.1 all compile it. What is going

    on?
    > Has the standard changed recently?
    >
    > john
    >
    >
     
    Ashok Viswanathan, Sep 5, 2003
    #2
    1. Advertising

  3. "Ashok Viswanathan" <> wrote in message
    news:U6X5b.4080$...
    > It is a bug in these compilers. HP's aCC compiler gives the expected

    error.
    > The other vendors are being milder.
    >


    Actually I found this

    http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45

    the standard is going to change in this regard. I guess gcc, Comeau and VC++
    are anticipating the change while aCC is not.

    John
     
    John Harrison, Sep 5, 2003
    #3
  4. John Harrison

    David White Guest

    "John Harrison" <> wrote in message
    news:bj9h3p$ghanq$-berlin.de...
    >
    > Actually I found this
    >
    > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45


    That's quite a document. I recently decided to part with $18 for the
    standard. Can I get my money back? :) I wonder how many of the
    standard-specialists who post here are up with all this.

    DW
     
    David White, Sep 5, 2003
    #4
  5. "David White" <no.email@provided> wrote in message
    news:JnY5b.2377$...
    > "John Harrison" <> wrote in message
    > news:bj9h3p$ghanq$-berlin.de...
    > >
    > > Actually I found this
    > >
    > > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45

    >
    > That's quite a document. I recently decided to part with $18 for the
    > standard. Can I get my money back? :) I wonder how many of the
    > standard-specialists who post here are up with all this.
    >
    > DW
    >


    I expect most are at least aware of the defect reports. A handy summary of
    the important ones would be useful though.

    Most of the time I rely on my intuition and experience to answer questions
    about C++, thinking that if its an area I don't know anything about then
    I'll at least know I don't know. I've made quite a few mistakes recently
    though, mostly caused by the language having changed in recent years.

    john
     
    John Harrison, Sep 5, 2003
    #5
  6. John Harrison

    llewelly Guest

    "John Harrison" <> writes:

    > "David White" <no.email@provided> wrote in message
    > news:JnY5b.2377$...
    >> "John Harrison" <> wrote in message
    >> news:bj9h3p$ghanq$-berlin.de...
    >> >
    >> > Actually I found this
    >> >
    >> > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45

    >>
    >> That's quite a document. I recently decided to part with $18 for the
    >> standard. Can I get my money back? :) I wonder how many of the
    >> standard-specialists who post here are up with all this.
    >>
    >> DW
    >>

    >
    > I expect most are at least aware of the defect reports. A handy summary of
    > the important ones would be useful though.
    >
    > Most of the time I rely on my intuition and experience to answer questions
    > about C++, thinking that if its an area I don't know anything about then
    > I'll at least know I don't know. I've made quite a few mistakes recently
    > though, mostly caused by the language having changed in recent years.


    Note a large portion of the known issues (but, strangely, not #45,
    though its resolution has been stable since 04/01) were resolved
    in time for C++2003. The 2003 standard should be availible soon.
     
    llewelly, Sep 7, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Razvan
    Replies:
    5
    Views:
    11,335
    Dale King
    Jul 27, 2004
  2. kelvSYC
    Replies:
    2
    Views:
    603
    Chris Smith
    Aug 18, 2004
  3. Tony Johansson

    Nested classes within other classes

    Tony Johansson, Dec 14, 2004, in forum: C++
    Replies:
    2
    Views:
    494
    msalters
    Dec 14, 2004
  4. Chad E. Dollins
    Replies:
    3
    Views:
    669
    Kai-Uwe Bux
    Nov 8, 2005
  5. Torben Laursen

    Block access to zip files using access rules

    Torben Laursen, May 12, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    bruce barker
    May 12, 2008
Loading...

Share This Page