Originally Posted by
Elysia
Code:
enum class BoardPos_t { X, O, Blank };
std::array<BoardPos_t, 9> BoardPos;
// Remember that arrays start from 0, so pos 6 = 5 from 0.
BoardPos.at(5) = BoardPos_t::X;
BoardPos.at(8) = BoardPos_t::O;
Ah, I think I see.
Code:
BoardPos.at(5) = BoardPos_t::X;
would be written instead of:
Code:
int boardPos4 = cross;
Now, I will look at that link later. There is one more thing that confuses me from Jumping Into C++
Code:
enum RainbowColor { //I know, should be class, taken from book as is
RC_RED, RC_ORANGE, RC_YELLOW, RC_GREEN, RC_BLUE, RC_INDIGO, RC_VIOLET
};
RainbowColor chosen_color = RC_RED;
If I can use:
Code:
//EXAMPLE A
BoardPos.at(5) = BoardPos_t::X;
this is using BoardPos_t directly so to speak, not a variable of BoardPos_t.
In the book, what is the point/s of having a variable of the new enum type (variable 'chosen_color' above) if you can access the enum values directly like in EXAMPLE A?
In other words, do you ever need a variable of your custom enum type in C++11? I hope this makes sense.
Thanks.