Anonymous Enumeration to Stream
I want to overload the standard << operator, to let me send anonymous enumeration types to an ostream. I tried:
std::ostream& operator<<( std::ostream&, const enum& )
but it said it gives me a parse error, any help would be appreciated (before anyone suggests it, yes I have to use anonymous enumeration as the type is not part of my code, so switching to standard enumeration types is not an option).
Thanks in advance,
Dan
I know... but I don''t want them to simply output to stream as integers, I want them to output as descriptive text.
Yeah... I don''t think enum is a real type.. I was just wondering if there is a way to do it. My initial though was it might be possible... then my second thought was that it wouldn''t be. No terrible loss either way I guess.
roughly:
then just "cout << some_enum_wrapper(enum_value)"
typedef enum { A, B, C, D } some_enum;class some_enum_wrapper { some_enum val;explicit some_enum_wrapper(int v):val(v) { }operator<<(blahblahblah) {switch(v){case A:stream << "A";// etc}}}
then just "cout << some_enum_wrapper(enum_value)"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement