473,394 Members | 1,841 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,394 software developers and data experts.

public enum in abstract class?

I've got an abstract class (say foo) and I'd like to define an Enum (say
bar) within that class so that I can then refer to foo.bar.<one of the enum
labels> from within other parts of the program. The enum is *public* in
other words.

What I find is that while the compiler allows the enum declaration within
the abstract class, it turns out that the enum type isn't visible from
outside the class. It is visible from within descendant classes, as though
it were "protected" rather than public.

So, is this expected behavior? If so, then why doesn't the compiler complain
about the

public enum foo ...

that occurs within the abstract class? If not expected behavior, is this a
compiler bug?

Finally, given that what I want doesn't work, what's the "best practice"
here? I have an abstract property of the foo type, so descendant types must
provide that property. I want other classes to be able to access this
property; thus they need to be able to reference the type.

Bill
Nov 16 '05 #1
1 4665
Bill,

What is the visibility of the abstract class that contains the
enumeration?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bill Cohagan" <co*****@teraXNOSPAMXquest.com> wrote in message
news:uT**************@TK2MSFTNGP09.phx.gbl...
I've got an abstract class (say foo) and I'd like to define an Enum (say
bar) within that class so that I can then refer to foo.bar.<one of the
enum
labels> from within other parts of the program. The enum is *public* in
other words.

What I find is that while the compiler allows the enum declaration within
the abstract class, it turns out that the enum type isn't visible from
outside the class. It is visible from within descendant classes, as though
it were "protected" rather than public.

So, is this expected behavior? If so, then why doesn't the compiler
complain
about the

public enum foo ...

that occurs within the abstract class? If not expected behavior, is this a
compiler bug?

Finally, given that what I want doesn't work, what's the "best practice"
here? I have an abstract property of the foo type, so descendant types
must
provide that property. I want other classes to be able to access this
property; thus they need to be able to reference the type.

Bill

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nobody | last post by:
Hi All, In my application I have the following implementation for ClassA and ClassC invoking a call on ClassB. void ClassA::DoSomething() { int value = m_pClassB->Read(enum1); }
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
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: Alan Cobb | last post by:
Hi, In the managed C++ class below I get compile warning C4677 from VS2003. "signature of non-private function contains assembly private type", even though the managed enum is public. I have...
7
by: tron.thomas | last post by:
Please consider the following code: class Abstract { public: virtual ~Abstract() {} virtual void Method() = 0; }; class Concrete : public virtual Abstract
8
by: Jordan | last post by:
AFAIK there are two ways to expose members of a base class to a derived or child class: 1. declare the members public in the base class 2. declare them as 'protected' in the base class Is...
5
by: pali | last post by:
Hi, I was just wondering, why is not possible to make a member of a class BOTH abstract and static? MSDN says just that's in an error, not why this is so. In a nutshell, I need this: I have an...
1
by: =?Utf-8?B?d3BjbWFtZQ==?= | last post by:
I got the following code public ref class A { value struct PrivateType sealed { Int32 id; }; public: ref struct B abstract sealed { static const PrivateType x = {1}; static const PrivateType...
2
by: NullQwerty | last post by:
Hey folks, So, I've got three enum types: enum enum1 enum enum2 enum enum3 And then I've got a function overloaded three times to accept each enum type: private void func(enum1 myenum){}
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.