Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 21 Mar 2012 04:06 PM |
I have a few questions about enumerators in C++.
1. In ROBLOX, I believe that you can do: game.Workspace.Part.RightSurface = "Weld". In C++, you do: int variable = Lol. Is this just the standard syntax for C++ or is there a way to do: int variable = "Lol", and it will return the same result.
2. Is it possible for an enumerator to hold any data type other than numerical ones (such as strings)?
3. Does an enum have indices? |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 21 Mar 2012 04:09 PM |
for 1 and 2:
http://msdn (DOT) microsoft (DOT) com/en-us/library/2dzy4k6e(v=vs (DOT) 71) (DOT) aspx |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 04:12 PM |
Enums, simply put, are variable types you create that can only hold specific values.
For instance:
enum Answer {yes,no};
Answer cake = yes;
cake = no;
etc.
In the end of the day they're just usually integers and each value corresponds to some integer number. Most probably in this case, yes = 0 and no = 1. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 21 Mar 2012 04:38 PM |
@myrkos,
Then enums are pure nooby. What is a time when they are actually useful? |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 21 Mar 2012 04:40 PM |
@Flurite,
Would you rather memorize what error code 1, 512, and 44 do or see something that you can understand? The same goes for a ton of things besides error codes. It's primarily for values that have a limited range. |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 21 Mar 2012 04:41 PM |
| Okay, so for readability enums are good. |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 21 Mar 2012 04:43 PM |
It's good for setting options using bit stuff:
enum {cake = 1,pie = 2,cheese = 4,pizza = 8} food;
food = cake | pie | pizza; |
|
|
| Report Abuse |
|
|
Flurite
|
  |
| Joined: 03 Apr 2011 |
| Total Posts: 5386 |
|
|
| 21 Mar 2012 04:48 PM |
| o_O, I never saw enums like that before.. |
|
|
| Report Abuse |
|
|
Varp
|
  |
| Joined: 18 Nov 2009 |
| Total Posts: 5333 |
|
|
| 21 Mar 2012 05:11 PM |
You could write a class that accepts
T x = "lol";
and acts like an enum. The question, though, is "Should you?", to which the answer is, "Almost certainly not."
Enums are really useful just for basically defining a bunch of named constants that support the operations == and !=. In addition to that, tricks like what myrkos shows are useful too (even better in C++11, since you get to decide the underlying type of an enum). |
|
|
| Report Abuse |
|
|