Private enum in class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Vinokur

    #1

    Private enum in class


    --- 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://sourceforge.net/users/alexvn

  • Mehturt@gmail.com

    #2
    Re: Private enum in class


    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

    Comment

    • Ian Collins

      #3
      Re: Private enum in class

      Mehturt@gmail.c om 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.

      Comment

      Working...