Jump to content
  • Advertisement

Archived

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

dmounty

Anonymous Enumeration to Stream

This topic is 5489 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
I know... but I don''t want them to simply output to stream as integers, I want them to output as descriptive text.

Share this post


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

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!