cmake+gcc解决extended initializer lists only available with -std=c++11 or -std=gnu++11
来源:互联网 发布:混沌与秩序2救赎数据库 编辑:程序博客网 时间:2024/05/17 21:40
有时,我们需要一个结构体变量做为参数传递给函数,后面又不需要再用到这个结构体变量,所以如果专门定义一个变量,再将这个变量传递给函数就显得挺罗嗦。
就像下面这段代码,tmpStruct
只是起到一个数据包装的作用,调用test()
之后并不再用到,所以这个变量就显示有些多余 。
#include <iostream>struct _stA{ char *a; int b; int c;}stA;void test(_stA n){ cout<<n.a<<endl;}int main() { char str[]="hello!"; _stA tmpStruct{str,0,1};//定义一个变量装载str等数据; //或者写成_stA tmpStruct={str,0,1}也是可以的 test(tmpStruct);//将tmpStruct做为变量传递给test}
这时我们可以将数据包装成临时结构体变量(或者叫匿名变量)传递给要调用函数。所以调用方式可以简化成下面这样:
int main() { char str[]="hello!"; test(_stA{str,0,1});//编译器会为_stA{str,0,1}结构体生成一个临时变量}
但是重新编译,会出下面警告
J:\workspace\codemgr\cmimpl\testmd5.cpp: In function ‘int main()’:
J:\workspace\codemgr\cmimpl\testmd5.cpp:26:11: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
test(_stA{str,0,1});
它的意思大概就是_stA{str,0,1}这种用列表初始化结构的方式要在c++ 11标准中才支持。
initializer lists是c++11的特性 (参见 std::initializer_list(点击打开链接))
so,对于cmake生成的项目,我们就需要在CMakeLists.txt中添加如下编译选项
add_definitions(“-std=c++11”)
或者
add_definitions(“-std=gnu++11)
然后重新生成makefile,编译警告就消失了。
0 0
- cmake+gcc解决extended initializer lists only available with -std=c++11 or -std=gnu++11
- extended initializer lists only available with -std=c++11
- 关于make提示must be enabled with the -std=c++11 or -std=gnu++11 compiler options
- mod_tile编译出错 -std=c++11 or -std=gnu++11
- Linuxg++编译C++代码出错 -std=c++11 or -std=gnu++11
- -std=gnu++11 导致的问题
- gcc std=c99
- 关于-std=gnu++11的一篇文章
- -std=c++11
- GCC版本切换,-std=c++11问题
- Code::Blocks 12.11 error: ‘nullptr’ was not declared in this scope&GNU GCC -std=gnu++0x
- 问题:cc1plus.exe: error: unrecognized command line option '-std=gnu++11' compilation terminated due to
- g++ -std=c++11
- unrecognized command line option “ std=c 11”
- std::map initializer list syntax ?
- cenos 升级 g++ gcc(cc1plus: error: unrecognized command line option "-std=c++11")
- 如何写cmake使其包含c++11特性 (-std=c++11如何写进cmakeList.txt)
- g++配置选项-std=c++11
- JavaScript Core -- 事件
- Android沉浸式状态栏简单实现
- hdu 5500 Reorder the books
- 类模板与函数对象
- windows下administrator账户启用或关闭
- cmake+gcc解决extended initializer lists only available with -std=c++11 or -std=gnu++11
- CloudStack 4.4+KVM之KVM计算节点安装
- JavaScript Core -- 理解闭包
- 惯性导航之认识四元数(四)
- UML——包图
- 15.Swift 录制音频
- 使用 timeit 模块
- UML——对象图
- Bouguet极线校正进一步理解