About enums in C++
Where do c++ programmers usally write thier ENUM types?
lets say i got 5 enums, do i need to put each in diffrent header?
Color.h , something1.h , something2.h ?
enum Color { Red, Black };
enum something1 { ..., .... };
enum something2 { ..., .... };
enum something3 { ..., .... };
enum something4 { ..., .... };
Thats a very vague question to which there isn't really an answer.
I would say it depends on scope and relativeness to other enum types.
So do the enum want to be global, in namespace, in a class?
Is there any tie betweeen the enums or are you just polluting the scope?
I would say it depends on scope and relativeness to other enum types.
So do the enum want to be global, in namespace, in a class?
Is there any tie betweeen the enums or are you just polluting the scope?
You don't *need* to do it any particular way. If you really felt the need, you could put absolutely everything into a single source file. That would be a really bad idea, but you still could [smile]
Generally an enum doesn't make much sense on its own, it's usually associated with something. That something could be a set of flags to be passed to a function, for example. So the logical thing to do is to keep your enum in the same headers as that 'something' that it's associated with.
Generally an enum doesn't make much sense on its own, it's usually associated with something. That something could be a set of flags to be passed to a function, for example. So the logical thing to do is to keep your enum in the same headers as that 'something' that it's associated with.
yeah, there really isn't one specific way to arrange your enums. Logcally as joanusdmentia has said, an enum that is part of a class and/or function should logically be in the same header as that class/function. But of course not all enums are associated with one specific class/func. For example an enum that enumerates the keyboard keys - which is quite common should probably get it's own header file. Because this enum will be necessary in many different source files. But then again, maybe it's just part of your one window class and since all key presses are filtered in through the window class, you just need it in the header corresponding with your window class... So there's a valid case for both.
In short, do what you think feels right.
In short, do what you think feels right.
Welll...i think u should use one header for it if you are writing an specific application.....
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement