Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

passing enums in funtions ??

This topic is 2909 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

from what i can tell , enums are the best way for states in a program.


i am writing classes and whould like to pass enums in the arguments and use them as return types as well.

the only problem is that i would have to declare them as a global, is there another better way around this problem.

other wise i would have lots of emums as globals and from what i can tell that would get messy

Share this post


Link to post
Share on other sites
Advertisement

class A
{
public:
enum abc { a, b, c };
};

class B
{
A::abc s;

void use_abc(A::abc e)
{
s = e;
e = A::a;
}
};

Share this post


Link to post
Share on other sites
You can declare an enum in the public interface of a class. I don't know if this is good practice but I do it all the time, as long as the enum relates only to that class.

Share this post


Link to post
Share on other sites
Globals are frowned upon because 100 different pieces of code can modify them and you don't know which code did it.

Enums definitions are just definitions so it's not so bad to make them global. If you feel the enum is independent of any class then go ahead. I could be overlooking some obvious design principle though.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!