passing enums in funtions ??

Started by
3 comments, last by Zahlman 13 years, 6 months ago
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
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;   }};
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.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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.


You could also put the enum in its own namespace.

This topic is closed to new replies.

Advertisement