473,499 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enum

13 New Member
Hi there,

I'm fairly new at this, and I am having a bit of trouble wrapping my head around some concepts of enum for a project. So any help would be greatly appreciated.

Essentially I'm writing a program where i will have an enum in one of my classes. When the program is used, the user will define what actually goes inside the enum.
So for example what I mean is if the class is WorkDay....and the user defines what days of the weeks he or she works. One user would say monday, tuesday and thursday...and the class would look like:

class WorkDay{
enum days { monday, tuesday, thursday };
}

Another user might say monday, wednesday, thursday and friday....and the class would look like:

class WorkDay{
enum days { monday, wednesday, thursday, friday};
}


My question is....well....how do I actually code that?
How do I define what goes inside the enum each time the program is run through the user's input??

Another question is....how do I assign the enum constants to variables when it's inside a class?
Do I use something like:

WorkDay enum today = sunday; //???

And one final question....how do I actually output the enum constant?
If I want to output the above variable 'today'...it has already been enumerated...so it would output an number. But what if I want to output the word 'sunday' instead?


Sorry to bombard everyone with all of these questions. I'm just really confused with the basic concepts right now.

Thanks a lot for your help.
Apr 10 '07 #1
4 1927
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
To clarify ur first question
1)enums have to be specified at compile time and cant be specified on the go during run time
2)You can maintain a map to do this.


Thanks
Raghuram
Apr 10 '07 #2
Banfa
9,065 Recognized Expert Moderator Expert
And one final question....how do I actually output the enum constant?
If I want to output the above variable 'today'...it has already been enumerated...so it would output an number. But what if I want to output the word 'sunday' instead?
Almost everytime I create an enum I also create a function that takes the enum as an input and returns a const char * with the textual name of the enum entries to facilitate output and debugging.
Apr 10 '07 #3
cpp
5 New Member
Hi,

Answer to your second question."how do I assign the enum constants to variables when it's inside a class?"

you can do it inside the constructor of that class..just like assigning any normal variable a value

answer to your last Q:
You can use a switch statement, where cases include your enumerated consts and for each const you can print corresponding name
Apr 10 '07 #4
ice8595
13 New Member
thank you!!
Apr 11 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

20
4782
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...
21
4568
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
3561
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();...
18
11294
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
3384
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
13
12358
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
10
3865
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. ...
1
2440
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
2103
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
34
11126
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...
0
7128
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
7006
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
7169
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
7385
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
5467
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,...
1
4917
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4597
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.