Oct 14, 2015 at 6:11pm
enum Ship
{
SHIP_BATTLESHIP,
SHIP_AIRCRAFT_CARRIER,
SHIP_CARGO_SHIP,
SHIP_DESTROYER,
SHIP_BARGE,
SHIP_TUGBOAT,
};
How do I add SHIP_TITANIC to the list? I have tried static cast and it doesnt work/am not doing it right:
Oct 14, 2015 at 9:47pm
What does this statement do? 5 of what? What equals 5? |
Color color = COLOR_CYAN;
Last edited on Oct 14, 2015 at 9:48pm
Oct 15, 2015 at 2:24pm
Color color = COLOR_CYAN;
but we already knew that from our list right?
Oct 15, 2015 at 2:34pm
Um... no. Your so-called "list" doesn't say anything about a variable called color.
Your enum statement is defining a type called Color.
This:
Color color = static_cast<Color>(5); // ugly
declares a variable called color of that type, and initialises its value to COLOR_CYAN.
This:
Color color = COLOR_CYAN;
does exactly the same thing.
EDIT: A little part of me dies inside every time I have to use the American spelling of "colour" :P
Last edited on Oct 15, 2015 at 2:35pm
Oct 16, 2015 at 3:13pm
SHIP_BATTLESHIP = ship;
What are you trying to do here? This statment is equivalent to -5 = ship;
Oct 16, 2015 at 3:16pm
SHIP_BATTLESHIP = ship;
changed to this:
SHIPS SHIP_BATTLESHIP = ship
I am trying to allow the user to input and change the enum value.
Last edited on Oct 16, 2015 at 3:17pm
Oct 16, 2015 at 3:23pm
You can't do that. That's like asking the user to enter a new value for the number "-5".
In your enum definition, you're telling the compiler that the symbol SHIP_BATTLESHIP means "-5". You can't change that at runtime.
Why would you even want the user to be able to change that value? What purpose would it serve?
Last edited on Oct 16, 2015 at 3:23pm