1

Suppose I have an enum class

enum class ENUM{ A, B, C};

And I want to have a switch statement. So I get

char c = 'B';
ENUM e = ENUM::A;
switch(e) {
    case A:
    break;
    case B:
    break;
    case C:
    break;
}

The case could never be B. But how to convert value c to be enum value?

3
  • 1
    char B is 0x42, ENUM::B is 1. Commented Oct 29, 2022 at 22:10
  • 2
    "... But how to convert value c to be enum value?" create a mapper class, that supports that conversion. Commented Oct 29, 2022 at 22:10
  • @273K good hint! Commented Oct 29, 2022 at 22:10

2 Answers 2

1

What about

enum class ENUM{ A = 'A', B = 'B', C = 'C' };

?

Sign up to request clarification or add additional context in comments.

Comments

1

You said "convert c to enum value", so I assume you want to use Switch statement with a character.

You may just switch (c).

1 Comment

except that the value of c in this case will not be a value of a member of the enum

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.