473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Nov 6 '06 #1
2 8491

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
5
by: Andrea Williams | last post by:
I'm working with C# and I'm setting up some ENUM's I have a data and Business layer. I'm declaring a common enum for the Data Layer. The UI layer references the Bus layer and the bus layer...
1
by: Fredrik Strandberg | last post by:
Hi! I would highly appreciate some help with how to access an enumeration declared as private in a class from the outside of the class. This is a simplified example of the situation: Const...
6
by: Valmont | last post by:
Complete newbie at C#. Class below stripped for brevity. How do I return a private "Status" from a public method? I may need a set/get but I don't know how to do that on an enum. Thank you....
7
by: Dick | last post by:
I have some simple (private) types... Friend Enum Types Value1 Value2 End Enum Friend Structure Detail Dim Type As Types End Structure
13
by: toton | last post by:
Hi, I have some enum (enumeration ) defined in some namespace, not inside class. How to use the enum constant's in some other namespace without using the whole namespace. To say in little...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
6
by: bw171 | last post by:
I got some java code below, and upon trying to compile it in my unix environment, i get the following error ()> javac Downloader.java Downloader.java:37: ';' expected private enum...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.