Luc*_*ini 2 c++ warnings compiler-warnings c++11
我第一次使用动态分配,编译器给了我这个警告,我在其他地方找不到:
warning: non-static data member initializers only available with
-std=c++11 or -std=gnu++11
Run Code Online (Sandbox Code Playgroud)
有没有办法让它消失?我应该关心吗?谢谢!
问题:
它与动态分配无关.
您可能正在使用此方法之一进行数据成员初始化,这是C++ 11的一部分:
class S
{
int n; // non-static data member
int& r; // non-static data member of reference type
int a[10] = {1, 2}; // non-static data member with initializer (C++11)
std::string s, *ps; // two non-static data members
struct NestedS {
std::string s;
} d5, *d6; // two non-static data members of nested type
char bit : 2; // two-bit bitfield
};
Run Code Online (Sandbox Code Playgroud)
编译器告诉您正在使用仅存在于C++ 11(及更高版本)中的功能(非静态数据成员初始化程序).
解决问题:
-std=c++11flag 编译代码.我应该关心吗?
绝对没错.不注意警告可能会导致许多问题,如溢出和未定义的行为.