Elronnd Elronnd - 1 year ago 104
C++ Question

Issue with initializer list for vector of an enum class

I have an enum, and a couple of vectors of some of the contents of the enum. I want to change the enum to an enum class, for type safety, but I'm getting errors. Consider the following snippet:

#include <vector>

enum Colour {

int main() {
const std::vector<Colour> something { red, green };
return 0;

It works fine. However, if I change the enum to an enum class, I get errors such as
error: ‘green’ was not declared in this scope
. What can I do?

ee2 ee2
Answer Source

Use Color::green for enum classes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download