Using bitwise operators in switch case

abc abc 351 Reputation points
2020-09-01T11:00:46.357+00:00

I have enum,
enum ENUM_MSG_TEXT_CHANGE {COLOR=0,SIZE,UNDERLINE};

void Func(int nChange)
{
switch(nChange)
{
case COLOR:break;
case SIZE:break;
case COLOR|SIZE: break
}

}

case SIZE: and case COLOR|SIZE both gives value 1, so I am getting error error C2196: case value '1' already used. how to differenciate these two cases in switch case?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,753 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 45,691 Reputation points
    2020-09-01T11:20:01.18+00:00

    Start the enumeration with COLOR=1


  2. RLWA32 45,691 Reputation points
    2020-09-01T11:52:07.52+00:00

    Try this

    enum ENUM_MSG_TEXT_CHANGE { COLOR = 1, SIZE = 2, UNDERLINE = 4, ITALIC = 8, UGLY = 16, PRETTY = 32, AWESOME = 64 };
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.