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.

Wishes for enum in future builds

When the enum inherients a type it would be nice not to have to do a cast to
that type.
enum MyEnum: int{one=1,two=2}
MyEnum Mine = 1; // no error!

It would be nice to constrain an enum to a function call (makes code easier
to read, and prevents bad calls)
public int MyRouting(enum inEnum{one=1, two=2} ){ return (int)inEnum;}
int i = MyRoutine(one); // enum would only have scope in routine and calls
to routine

Mar 7 '06 #1
1 1136
GRiN <GR**@discussions.microsoft.com> wrote:
When the enum inherients a type it would be nice not to have to do a cast to
that type.
It *doesn't* inherit from a type though.
enum MyEnum: int{one=1,two=2}
MyEnum Mine = 1; // no error!
Please no! That reduces the type safety of it. The whole point of enums
are that they're separate types.
It would be nice to constrain an enum to a function call (makes code easier
to read, and prevents bad calls) public int MyRouting(enum inEnum{one=1, two=2} ){ return (int)inEnum;}
int i = MyRoutine(one); // enum would only have scope in routine and calls
to routine


Looks like a bit of a readability-killer to me. If you need an enum,
make it a proper type.

For my wishlist on enums, however, see
http://msmvps.com/blogs/jon.skeet/ar...classenum.aspx

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 7 '06 #2

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

Similar topics

9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
3
by: Matt | last post by:
Hi, Recently we had some code like this cause a failure: MyEnum myEnum = (MyEnum) (int) dt; i.e. reading an int out of the database and casting it into a type-safe enum. The thought...
3
by: ssg31415926 | last post by:
I have an abstract base class with an enum which is passed into a method. I want my derived classes to be able to add new values to the enum without having to redefine it and I want to be able to...
2
by: Robert W. | last post by:
In a posting earlier this year I found a simple approach to convert a string to a particular Enum value. The one line solution looked like this: MyEnum ConvertedString = (MyEnum)...
4
by: veerleverbr | last post by:
Suppose having define an enum like this: public enum SomeEnum { Something, SomethingElse }
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...
12
by: Cmtk Software | last post by:
I'm trying to define an enum which will be used from unmanaged c++, C++/CLI managed c++ and from C#. I defined the following enum in a VS dll project set to be compiled with the /clr switch: ...
13
by: Rohit | last post by:
Is there any way by which I can find number of elements in an enum list? Generally I use one last element at the end to find out total number of elements. e.g. typedef enum{ SUN, MON, TUE,...
0
by: tony_in_da_uk | last post by:
*** I posted this on comp.lang.c++.moderated a couple days ago, and got a near-flippant response from someone who clearly didn't take the time to consider the import. I replied, and it's still not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: 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
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
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
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
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.