小编Tos*_*hko的帖子

初始化指向结构的指针 - 编译器警告

#include <iostream>
using namespace std;

struct test
{
   int factorX;
   double coefficient;
};

int main()
{
   test firstTest = {1, 7.5}; //that's ok

   test *secondTest = new test;
   *secondTest = {8, 55.2}; // issue a compiler warning

}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么编译器发出以下警告:

test2.cpp:13:33: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
test2.cpp:13:33: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
Run Code Online (Sandbox Code Playgroud)

我知道在C++ 11中我可以省略赋值运算符,但事实并非如此.我正在使用g ++ 4.7.2.

c++ struct warnings g++ c++11

3
推荐指数
1
解决办法
2180
查看次数

标签 统计

c++ ×1

c++11 ×1

g++ ×1

struct ×1

warnings ×1