943,630 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 2833
  • C++ RSS
Feb 18th, 2007
0

multiple enums problem

Expand Post »
C++ Syntax (Toggle Plain Text)
  1. enum MenuOptionInitial { TEST_ONE = 1, TEST_TWO, TEST_THREE};
  2.  
  3. switch(selection)
  4. {
  5. case TEST_ONE:
  6. //....
  7. case TEST_TWO:
  8. //....
  9. case TEST_THREE:
  10. //....
  11. }

the problem is that i want to have another selection base on other options

C++ Syntax (Toggle Plain Text)
  1. i.e.
  2. enum MenuSecond { TEST2_ONE = 1, TEST2_TWO, TEST2_THREE};
  3.  
  4. switch(another_selection)
  5. {
  6. case TEST2_ONE:
  7. //....
  8. case TEST2_TWO:
  9. //....
  10. case TEST2_THREE:
  11. //....
  12. }

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?
Similar Threads
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006
Feb 18th, 2007
0

Re: multiple enums problem

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:
  1. enum MenuOne { MO_FIRST = 1, MO_SECOND } ;
  2. enum MenuTwo { MT_FIRST = 1, MT_SECOND } ;
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Feb 19th, 2007
0

Re: multiple enums problem

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)
  1. const ENUM_ONE_START = 0 ;
  2. const ENUM_TWO_START = ENUM_ONE_START + 100 ;
  3.  
  4. enum MenuOptionInitial { TEST_ONE = ENUM_ONE_START, TEST_TWO, TEST_THREE};
  5. enum MenuSecond { TEST2_ONE = ENUM_TWO_START, TEST2_TWO, TEST2_THREE};
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Feb 21st, 2007
0

Re: multiple enums problem

Click to Expand / Collapse  Quote originally posted by thekashyap ...
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)
  1. const ENUM_ONE_START = 0 ;
  2. const ENUM_TWO_START = ENUM_ONE_START + 100 ;
  3.  
  4. enum MenuOptionInitial { TEST_ONE = ENUM_ONE_START, TEST_TWO, TEST_THREE};
  5. enum MenuSecond { TEST2_ONE = ENUM_TWO_START, TEST2_TWO, TEST2_THREE};
thanks for answering
Reputation Points: 23
Solved Threads: 12
Posting Whiz in Training
n.aggel is offline Offline
202 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: can anybody help me with this
Next Thread in C++ Forum Timeline: gcc on windows-linking problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC