• Advertisement

Archived

This topic is now archived and is closed to further replies.

Anonymous Enumeration to Stream

This topic is 5315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
roughly:

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)"

Share this post


Link to post
Share on other sites

  • Advertisement