Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enum type in C++

Tags:

c++

enums

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?

like image 632
httpinterpret Avatar asked May 24 '26 11:05

httpinterpret


2 Answers

It works too, but you need explicit type

TPriority priority = (TPriority)-100;
like image 169
Victor Avatar answered May 26 '26 18:05

Victor


shortly put: it defeats the purpose of having an enum

like image 29
AndersK Avatar answered May 26 '26 17:05

AndersK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!