首页 > 解决方案 > 用 g++ 5.4 编译 C++11

问题描述

-std=c++11编译时似乎被忽略:

    g++ -std=c++11 -I../include -I ../../../Toolbox/CShmRingBuf/ -I$MILDIR/include CFrameProd.cpp -o CFrameProd.o
CFrameProd.cpp: In constructor ‘CFrameProd::CFrameProd()’:
CFrameProd.cpp:33:24: error: assigning to an array from an initializer list
     MilGrabBufferList_ = {0};

我试过-std=c++0x, -std=gnu++0x, -std=c++14了,没有任何帮助。

这是我的 g++ 版本:

g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我怎样才能让它工作?

标签: c++c++11

解决方案


代码似乎在数组声明之后将初始化列表分配给数组地址,如下所示:

int main()
{
    long int foo[5];
    foo = {0};
}

这会产生错误:assigning to an array from an initializer list

相反,它应该是这样的:

int main()
{
    long int foo[5] = {0};
}

在您的情况下,它将是:long MilGrabBufferList_[10] = {0};


推荐阅读