access rules and nested classes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Harrison

    access rules and nested classes

    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

    #2
    Re: access rules and nested classes

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

    "John Harrison" <john_andronicu s@hotmail.com> wrote in message
    news:bj99kn$gap 5a$1@ID-196037.news.uni-berlin.de...[color=blue]
    > 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[/color]
    on?[color=blue]
    > Has the standard changed recently?
    >
    > john
    >
    >[/color]


    Comment

    • John Harrison

      #3
      Re: access rules and nested classes


      "Ashok Viswanathan" <ashok.viswanat han@hp.com> wrote in message
      news:U6X5b.4080 $4c.1896@news.c pqcorp.net...[color=blue]
      > It is a bug in these compilers. HP's aCC compiler gives the expected[/color]
      error.[color=blue]
      > The other vendors are being milder.
      >[/color]

      Actually I found this



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

      John


      Comment

      • David White

        #4
        Re: access rules and nested classes

        "John Harrison" <john_andronicu s@hotmail.com> wrote in message
        news:bj9h3p$gha nq$1@ID-196037.news.uni-berlin.de...[color=blue]
        >
        > Actually I found this
        >
        > http://anubis.dkuug.dk/jtc1/sc22/wg2...efects.html#45[/color]

        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



        Comment

        • John Harrison

          #5
          Re: access rules and nested classes


          "David White" <no.email@provi ded> wrote in message
          news:JnY5b.2377 $d6.125675@nasa l.pacific.net.a u...[color=blue]
          > "John Harrison" <john_andronicu s@hotmail.com> wrote in message
          > news:bj9h3p$gha nq$1@ID-196037.news.uni-berlin.de...[color=green]
          > >
          > > Actually I found this
          > >
          > > http://anubis.dkuug.dk/jtc1/sc22/wg2...efects.html#45[/color]
          >
          > 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
          >[/color]

          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


          Comment

          • llewelly

            #6
            Re: access rules and nested classes

            "John Harrison" <john_andronicu s@hotmail.com> writes:
            [color=blue]
            > "David White" <no.email@provi ded> wrote in message
            > news:JnY5b.2377 $d6.125675@nasa l.pacific.net.a u...[color=green]
            >> "John Harrison" <john_andronicu s@hotmail.com> wrote in message
            >> news:bj9h3p$gha nq$1@ID-196037.news.uni-berlin.de...[color=darkred]
            >> >
            >> > Actually I found this
            >> >
            >> > http://anubis.dkuug.dk/jtc1/sc22/wg2...efects.html#45[/color]
            >>
            >> 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
            >>[/color]
            >
            > 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.[/color]

            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.



            Comment

            Working...