Search code examples
c++c++11non-staticdata-members

non-static data member initializers c++


non-static data member initializers only available with -std=c++11 or -std=gnu++11 
[enabled by default]
     int Red = 255;
non-static data member initializers only available with -std=c++11 or -std=gnu++11
[enabled by default]
     int Green = 255;
non-static data member initializers only available with -std=c++11 or -std=gnu++11 
[enabled by default]
     int Blue = 255;

Not sure why this doesn't work.

struct color {
    int Red = 255;
    int Green = 255;
    int Blue = 255;
};

Solution

  • Enable c++11 or:

    struct Color
    {
        int Red;
        int Green;
        int Blue;
        Color() : Red(255), Green(255), Blue(255) {}
    };