| | |
multiple enums problem
Thread Solved
![]() |
C++ Syntax (Toggle Plain Text)
enum MenuOptionInitial { TEST_ONE = 1, TEST_TWO, TEST_THREE}; switch(selection) { case TEST_ONE: //.... case TEST_TWO: //.... case TEST_THREE: //.... }
the problem is that i want to have another selection base on other options
C++ Syntax (Toggle Plain Text)
i.e. enum MenuSecond { TEST2_ONE = 1, TEST2_TWO, TEST2_THREE}; switch(another_selection) { case TEST2_ONE: //.... case TEST2_TWO: //.... case TEST2_THREE: //.... }
what can i do , for this to work??
i want to have multiple enums...is it possible....???
I think that i could use namespaces to solve this problem{although i don't know how}...But i someone wanted to write to pure c {that doesn't have namespaces}, what would he do?
Why not use the first ENUM set for the second selection also ?
Either that or prefix the ENUM names with an abbreviation of their purpose. Something like:
Either that or prefix the ENUM names with an abbreviation of their purpose. Something like:
c Syntax (Toggle Plain Text)
enum MenuOne { MO_FIRST = 1, MO_SECOND } ; enum MenuTwo { MT_FIRST = 1, MT_SECOND } ;
I don't accept change; I don't deserve to live.
As long as both enums are NOT used within same switch-case there are no issues at all..
If you wish to use them in same switch-case you'll get the err that case value is repeated. So all you gotta do is decide on 2 ranges for both your enums and change the first value in enum declaration appropriately.
E.g.
If you wish to use them in same switch-case you'll get the err that case value is repeated. So all you gotta do is decide on 2 ranges for both your enums and change the first value in enum declaration appropriately.
E.g.
c++ Syntax (Toggle Plain Text)
const ENUM_ONE_START = 0 ; const ENUM_TWO_START = ENUM_ONE_START + 100 ; enum MenuOptionInitial { TEST_ONE = ENUM_ONE_START, TEST_TWO, TEST_THREE}; enum MenuSecond { TEST2_ONE = ENUM_TWO_START, TEST2_TWO, TEST2_THREE};
•
•
•
•
As long as both enums are NOT used within same switch-case there are no issues at all..
If you wish to use them in same switch-case you'll get the err that case value is repeated. So all you gotta do is decide on 2 ranges for both your enums and change the first value in enum declaration appropriately.
E.g.
c++ Syntax (Toggle Plain Text)
const ENUM_ONE_START = 0 ; const ENUM_TWO_START = ENUM_ONE_START + 100 ; enum MenuOptionInitial { TEST_ONE = ENUM_ONE_START, TEST_TWO, TEST_THREE}; enum MenuSecond { TEST2_ONE = ENUM_TWO_START, TEST2_TWO, TEST2_THREE};
![]() |
Similar Threads
- Internet Explorer multiple windows problem - XP (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: can anybody help me with this
- Next Thread: gcc on windows-linking problem
| Thread Tools | Search this Thread |
anyfile api array based binary bitmap c++ c++borland c/c++ char class classes code coding compile console conversion count csimilaritybetweentext delete deploy desktop developer development directshow dll download draw dynamic dynamiccharacterarray email encryption error file forms fstream function functions game gdi+ givemetehcodez gnu graph gui homeworkhelp homeworkhelper http iamthwee ibm ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node output packing parameter pointer problem program programming project python random read recursion reference rpg string strings temperature template test text text-file tree url variable vector video visualc++ visualizationtoolkit win32 windows winsock wordfrequency wxwidgets






