enum aaa {a, b, c};
std::map <aaa, int> container;
container[0]; //compilation error
I know that in this case container is empty and I would get segfault, but that’s not the problem. Enum is arithmetic type so why there is a problem?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re wrong on both counts. 🙂
An
intis not implicitly convertible to anenum, an explicit cast is required, and you wouldn’t get a segfault, becausecontainer[0]would value-initialize a new value in the map.