Is there any potential problem that I should be aware of when casting an int to enum when the int is greater than the number of possible values, say
Here is the code snippet, which seems work well:) :
#include <iostream>
int main()
{
enum Demo{NONE=0, OK, HEART, OTHERS, FULL};
enum Demo demo = static_cast<enum Demo>(9);
std::cout << static_cast<int>(demo) << std::endl;
std::cout << (static_cast<int>(demo) == 9) << std::endl;
}
Aucun commentaire:
Enregistrer un commentaire