Using bitwise operators in switch case

abc abc 346 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.
2,626 questions
No comments
{count} votes

2 answers

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

    Start the enumeration with COLOR=1


  2. RLWA32 28,656 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 };
    
    No comments