What is a C++11 extension [-Wc++11-extensions]

后端 未结 1 1152
说谎
说谎 2020-12-15 10:06

I need some help understanding where this error is occurring:

warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11

相关标签:
1条回答
  • 2020-12-15 10:28

    That's not an error, it's a warning. It tells you that you're only allowed to initialize non-static members of a struct / class starting with the C++11 standard (so called because it was published in 2011). Before that, you weren't officially allowed to by C++98 (published, you've guessed it, in 1998). Long story short, what you're doing has only become legal, official C++ in 2011. Your compiler's default seems to be the 1998 standard.

    Try compiling with -std=c++11 as a command line flag (assuming you're using GCC or clang), and the warning should go away. If you're using a different compiler, there should be a flag for that as well (if it's recent enough to implement C++11).

    0 讨论(0)
提交回复
热议问题