c++ - 用 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.
我怎样才能让它工作?
解决方案
代码似乎在数组声明之后将初始化列表分配给数组地址,如下所示:
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};
推荐阅读
- security - Cross-Origin-Embedder-Policy:如何只允许某些域?
- docker - 来自同一网络上的主机名的容器请求
- ruby-on-rails - RAILS:ActiveRecord#persisted 吗?实际查询数据库?
- c# - EF Core 5.0 单向多对多关系,在依赖实体上没有阴影导航属性
- r - 添加具有自定义颜色的连续/离散 alpha 比例
- spring-boot - Spring webclient:使用新令牌重试
- python - 网页如何抓取以下 URL 引号中的数据
- python - 如何在 streamlit 中自定义数据框的可视化
- apache - 防止 Apache2 重定向到不同的端口
- javascript - 如何在 React 中将键盘事件与 div 元素绑定