By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,191 Members | 749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,191 IT Pros & Developers. It's quick & easy.

Private enum in class

P: n/a

--- 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

Nov 6 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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 '06 #2

P: n/a
Me*****@gmail.com 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.
Nov 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.