Private enum in class

Discussion in 'C++' started by Alex Vinokur, Nov 6, 2006.

  1. Alex Vinokur

    Alex Vinokur Guest

    --- File foo.cpp ---
    class Foo
    {
    private:
    enum Eoo { aaa, bbb, ccc };
    struct Soo
    {
    Eoo m_code;
    };
    };

    int main()
    {
    Foo f;
    return 0;
    }
    --------------------

    Compiler Green Hills C++ Version 4.0.6 produces the following error:
    "foo.cpp", line 7: error #265-D: enum "Foo::Eoo" is inaccessible
    Eoo m_code;
    ^

    Compiler Microsoft C++ Version 13.10.3077 (Visual C++ 7.1) has no
    problem with that code.

    Which is correct?

    Alex Vinokur
    email: alex DOT vinokur AT gmail DOT com
    http://mathforum.org/library/view/10978.html
    http://sourceforge.net/users/alexvn
     
    Alex Vinokur, Nov 6, 2006
    #1
    1. Advertising

  2. Alex Vinokur

    Guest

    Alex Vinokur wrote:
    > --- File foo.cpp ---
    > class Foo
    > {
    > private:
    > enum Eoo { aaa, bbb, ccc };
    > struct Soo
    > {
    > Eoo m_code;
    > };
    > };
    >
    > int main()
    > {
    > Foo f;
    > return 0;
    > }
    > --------------------
    >
    > Compiler Green Hills C++ Version 4.0.6 produces the following error:
    > "foo.cpp", line 7: error #265-D: enum "Foo::Eoo" is inaccessible
    > Eoo m_code;
    > ^
    >
    > Compiler Microsoft C++ Version 13.10.3077 (Visual C++ 7.1) has no
    > problem with that code.
    >
    > Which is correct?


    Comeau online has no problems as well.. I think it's perfectly legal
    for a class to have private enum.

    m
     
    , Nov 6, 2006
    #2
    1. Advertising

  3. Alex Vinokur

    Ian Collins Guest

    wrote:
    > Alex Vinokur wrote:
    >
    >>--- File foo.cpp ---
    >>class Foo
    >>{
    >>private:
    >> enum Eoo { aaa, bbb, ccc };
    >> struct Soo
    >> {
    >> Eoo m_code;
    >> };
    >>};
    >>
    >>int main()
    >>{
    >> Foo f;
    >> return 0;
    >>}
    >>--------------------
    >>
    >>Compiler Green Hills C++ Version 4.0.6 produces the following error:
    >>"foo.cpp", line 7: error #265-D: enum "Foo::Eoo" is inaccessible
    >> Eoo m_code;
    >> ^
    >>
    >>Compiler Microsoft C++ Version 13.10.3077 (Visual C++ 7.1) has no
    >>problem with that code.
    >>
    >>Which is correct?

    >
    >
    > Comeau online has no problems as well.. I think it's perfectly legal
    > for a class to have private enum.
    >

    It is, but that's not the problem here. The problem is the nested class
    Soo accessing a private type of its outer class.

    This wasn't strictly legal in the original 1998 standard, but I think
    this was either amended in the 2003 revision, or in a recent draft.

    --
    Ian Collins.
     
    Ian Collins, Nov 6, 2006
    #3
    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. -

    enum within an enum

    -, Jun 12, 2005, in forum: Java
    Replies:
    6
    Views:
    553
  2. Jerminia
    Replies:
    3
    Views:
    636
    Roedy Green
    Oct 7, 2005
  3. DaveLessnau
    Replies:
    3
    Views:
    430
    Howard
    May 16, 2005
  4. Brian
    Replies:
    4
    Views:
    2,664
    Brian
    Feb 27, 2010
  5. Ansel

    "enum" vs. "enum class"

    Ansel, Aug 26, 2012, in forum: C++
    Replies:
    16
    Views:
    757
    Ansel
    Aug 27, 2012
Loading...

Share This Page