Question 3
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
enum class Light { red, yellow, green };
int main() {
Light l = green;
std::cout << (l == Light::green) << '\n';
return 0;
}
- A Light must be an int
- B Enumerators of an enum class are scoped: write Light::green (or using enum Light; in C++20) Correct
- C green is a keyword
- D l must be const
Correct Answer: Option B
Scoping prevents clashes such as two enums both having red.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!