I have an enum like this: (Actually, it's an enum class)
enum class truth_enum {
my_true = 1,
my_false = 0
};
I would like to be able to expose my_true to the global namespace, so that I can do this:
char a_flag = my_true;
Or at least:
char a_flag = (char)my_true;
Instead of this:
char a_flag = truth_enum::my_true;
Is this possible?
I have tried something like this:
typedef truth_enum::my_true _true_;
I receive the error: my_true in enum class truth_enum does not name a type
My guess is that my_true is a value not a type. Is there an alternative which I can do to enable this functionality in my programs?
Not ideal, but I could do something like:
enum class : const char { ... };
const char const_flag_false = truth_enum::my_false;
Remove class
from the enum
definition. I'll assume that you are offended by implicit conversion to int
. How about:
static constexpr truth_enum _true_ = truth_enum::my_true;
static constexpr truth_enum _false_ = truth_enum::my_false;
or simply
const truth_enum _true_ = truth_enum::my_true;
const truth_enum _false_ = truth_enum::my_false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With