如何使用-Wall -02和-std=c++0x进行编译
How to compile with -Wall -02 and -std=c++0x
我想用- Wall -O2
和-std=c++0x
编译。当我编译没有-Wall -02
我有:typeof was undeclared in this scope
和it was undeclared in this scope
。当我编译我的代码没有需要-std=c++0x
的代码的一部分,一切都很好,但我想要这部分。怎么了?
需要- Wall -O2
:
for(typeof(g[node].begin()) it = g[node].begin(); it != g[node].end(); ++it)
需要-std=c++0x
:
的代码 auto biggest = std::max_element(std::begin(koszty), std::end(koszty));
和
avg = accumulate(czasy.begin(), czasy.end(), 0) / czasy.size();
没有命名为typeof
的操作符、关键字或标准函数。似乎你正在尝试使用c++ 11 decltype
结构。
使用auto
:
for(auto it = g[node].begin(); it != g[node].end(); ++it)
或者是基于范围的for
循环:
for (auto& val : g[node]) { ... }
就像注释所说的那样,你想使用的选项不是不兼容的,如果需要或想要使用它们,请使用它们。
ISO c++中没有提到标识符typeof
。它是C和c++的GNU扩展。它与-Wall
(控制警告的选项)或-O2
(控制优化的选项)无关。如果确实需要,您应该使用-std=gnu++0x
而不是-std=c++0x
来启用GNU方言。
然而,这似乎是不必要的。由于您使用的是c++ 0x(现在是c++ 11),关键字decltype
是正确且符合typeof
的替代品。但是为了清晰起见,我建议使用auto
相关文章:
- 二叉排序树无法编译
- 使用 C++0x 编译生成文件
- Unix 宏在使用 -std=c++0x 标志编译时变得未定义
- g++ 不会在 Snow Leopard 下编译 std=c++0x
- 编译时哈希C++0x
- 在 G++ 编译命令中包含 -std=c++0x 有什么意义?
- g++ 4.4.7 -std=gnu++0x 应该编译"for each"结构吗?
- 在Android-ndk(r7)中编译.cpp文件时如何打开"C++0X"实验标准?
- c++0x进行编译,但eclipse编辑器错误,即使使用了-gnu++0x发现
- 在c++中编译-std=c++0x需要什么?
- 启用-std=c++0x时,自定义分配器的编译问题
- 如何在mac上的Eclipse CDT上编译c++ 0x代码
- 是否有一个编译时函数/宏来确定c++ 0x结构体是否为POD
- c++不编译c++ 0x基于范围的for循环
- 如何使用-Wall -02和-std=c++0x进行编译
- 使用c++0x标志编译wxWidgets
- boost::bind到std::lower_bound可以工作,但是c++ 0x std::bind无法编译
- 使用clang编译libstdc++4.4.7和-std=c++0x时会失败
- 如果我包含"-ansi"编译器选项,为什么我的 C++0x 代码无法编译?
- Synology交叉编译GCC -std=c++0x