Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
It works too, but you need explicit type
TPriority priority = (TPriority)-100;
Add a comment
shortly put: it defeats the purpose of having an enum
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);
There is no type conversion from the values of an enum type to the enum type itself. Only the other way around.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.