class private variable error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;


class Ham{
    private:
        int bar = 1;
};


int main(){

    return 0;
}



It says "non static data member initializers"...

Someone said I need to add -std=c++0x, -std=c++11 or -std=c++1y.

but what do they do and why do I need to add them?
It works fine for me, Im guessing you use Eclipse? Im using Visual studios 2013.
um...i use g++ with command prompt.
Someone said I need to add -std=c++0x, -std=c++11 or -std=c++1y.

this is correct. -std means use the version of c++'s standard that comes after the ='s sign. the default for gcc c++ is 2003 iirc, which is pre c++0x, and c++0x is when inline member initializers became legal (before you had to do it in a constructor). c++0x is the name given to the experimental version of c++11, and really doesnt need to be used anymore. c++11 is the release of the c++ standard that caused many major changes and is probably the one you want. c++11 completely changed the language. c++1y is c++14, which isnt as major a change as c++11. now that i think about it, 1y might be the experimental version of c++14.

It works fine for me, Im guessing you use Eclipse? Im using Visual studios 2013.

those are ide's and have nothing to do with the issue at hand.
Topic archived. No new replies allowed.