Search code examples
c++eclipsec++11cygwineclipse-cdt

warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]


I've just installed the latest version of cygwin and eclipse luna in my machine. It's working fine and I'm able to run my projects. However when I build them I got warnings I don't understand. For example, here are the warnings from a header file "Sales_item.h" which I got from the site of a book "c++ Primer":

warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [enabled by default]
     Sales_item() = default;
                    ^
../src/Sales_item.h:70:27: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     unsigned units_sold = 0; // explicitly initialized
                           ^
../src/Sales_item.h:71:22: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     double revenue = 0.0;
                      ^
Finished building: ..

What do these warnings mean? Should I do something?


Solution

  • Add -std=c++0x, -std=c++11 or -std=c++1y to your compiler flags.

    You can see that the compiler says:

    defaulted and deleted functions only available with -std=c++11 or -std=gnu++11

    Example on compiling in the terminal:

    g++ -std=c++0x main.cpp -o myExe

    In Eclipse, as πάντα ῥεῖ suggested, you can do:

    Project ->Properties ->C++ Build ->Misc Options

    or, at mine Kepler Eclipse, one would right click on the project and then:

    Properties ->C++ Build -> Settings

    and in the Command textbox, you can see the compiler you are using. You can write the compiler flag there too.

    For more, read this answer, as suggested by Baum mit Augen.