I'm not asking how to convert an enum to a string. I'm asking why the scope of the fully qualified class name cannot be used in this particular case of converting an enum to a string.
I'm running into a problem with a macro that converts an enumeration to a string. For example color_class.h
class color_class
{
public:
enum colors_e { RED, GREEN, BLUE};
};
#define colors__TO_STRING(color) \
(color == color_class::RED) ? "RED" : \
(color == color_class::GREEN) ? "GREEN" : \
(color == color_class::BLUE) ? "BLUE" : "";
The trouble I'm having is that sometimes "color_class::RED" is the correct expression to use, but sometimes the color_class prefix is wrong. That's what I cannot figure out. I don't know why the fully qualified name does not always work. Certainly I could redefine the macro to check for both color_class::RED and RED, but if I'm always assigning a value of type colors a fully qualified name, why would that name get lost? Thanks for the explanation.
To further clarify, when I use gdb, I see the following output:
ptype test_color
type = enum color_class::colors_e {RED, GREEN, BLUE}
p test_color == RED
$1 = true
p test_color == color_class::RED
There is no field named 'RED'
p colors__TO_STRING(test_color)
There is no field named 'RED'
macro define color__SIMPLE_STRING(color) (color == RED) ? "RED" : (color==GREEN) ? "GREEN" : (color == BLUE) ? "BLUE" : "";
p color__SIMPLE_STRING(test_color)
$2 = ""