2

This works:

enum TPriority { EPriorityIdle = -100, EPriorityLow = -20, EPriorityStandard = 0, EPriorityUserInput = 10, EPriorityHigh = 20 }; TPriority priority = EPriorityIdle; 

But this doesn't work:

TPriority priority = -100; 

Any reason?

0

4 Answers 4

10

It works too, but you need explicit type

TPriority priority = (TPriority)-100; 
Sign up to request clarification or add additional context in comments.

Comments

4

shortly put: it defeats the purpose of having an enum

Comments

2

You cannot assign an int to an enum, even if the value matches one of the enum's values.

However, casting will work:

TPriority priority = static_cast<TPriority>(-100); 

Comments

0

There is no type conversion from the values of an enum type to the enum type itself. Only the other way around.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.