What is a modern C++ approach to structures containing symbolic constants?
Posted
by
Ken
on Stack Overflow
See other posts from Stack Overflow
or by Ken
Published on 2012-09-04T21:14:54Z
Indexed on
2012/09/04
21:38 UTC
Read the original article
Hit count: 195
c++
|data-structures
enum bool
{
FALSE = 0,
TRUE = 1
};
I'm wondering how to translate this in a modern C++ approach and if there is a well suited container for that; i know that the enum
are not really that appreciated, but i can't think about a real alternative in the C++ world.
What if would like to associate the execution of a particular method with a state?
Ok, this is the part where i will be more verbose.
I would like to stress the fact that i'm asking about structures symbolic constants and not about TRUE and FALSE, i'm not that "needy".
Suppose that i have a structure that can represent several states with their own constants
enum semaphore
{
GREEN = 0,
ORANGE = 1,
RED = 2
};
this is C code, now my question is about how to do the same in C++ if there is a better way.
My question continue when i ask about the possibility to do something like an automatic triggering when a change of state will occur, for example:
int main{
...
semaphore = 1;
...
}
and without any extra statements this has to trigger a method()
just because the semaphore is now orange.
I hope that is more clear now.
© Stack Overflow or respective owner