multiple enums problem

Thread Solved
Reply

Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 10
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

multiple enums problem

 
0
  #1
Feb 18th, 2007
  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

  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?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: multiple enums problem

 
0
  #2
Feb 18th, 2007
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 } ;
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: multiple enums problem

 
0
  #3
Feb 19th, 2007
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.
  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};
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 10
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: multiple enums problem

 
0
  #4
Feb 21st, 2007
Originally Posted by thekashyap View Post
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.
  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
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC