Is the default initialization/construction of enum classes defined behavior?
Here is a minimal example(Try Online)
enum class ALPHA{
X = 0,
Y = 1,
Z = 2,
};
int main()
{
ALPHA a = ALPHA(); // use default constructor
ALPHA b{}; // use default initialization
std::cout <<static_cast<int>(a) << std::endl; // 0
std::cout <<static_cast<int>(b) << std::endl; // 0
return 0;
}
I get zero in both cases. So does the default initialization pick the first enum type(eg. here X = 0) always? I know that it is UB for standard enums but Im not sure about the semantics for enum classes? I looked this up on CPPReference too but didnt find any relevant information about it - Is it possible to get a standard reference too?
Aucun commentaire:
Enregistrer un commentaire