Private enum in class

A

Alex Vinokur

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

Mehturt

Alex said:
--- 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
 
I

Ian Collins

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top