c++ - 如果包含 "-ansi"编译器选项,为什么我的 C++0x 代码无法编译?

标签 c++ c++11 g++ ansi

我遇到了一个非常奇怪的错误,只有在我使用 ansi 标志时才会弹出。

#include <memory>

class Test
{
  public:
    explicit Test(std::shared_ptr<double> ptr) {}
};

这是编译,使用 gcc 4.5.2 和 4.6.0 (20101127) 测试:

g++ -std=c++0x -Wall -pedantic -ansi test.cpp
test.cpp:6:34: error: expected ')' before '<' token

但是不用 ​​-ansi 编译也可以。为什么?

最佳答案

对于 GNU C++ 编译器,-ansi-std=c++98 的另一个名称,它覆盖了 -std=c++0x 你之前在命令行上。你可能只想

$ g++ -std=c++0x -Wall minimal.cpp

(-pedantic 在 C++ 中默认开启,所以没必要再说一遍。如果你想要更挑剔的警告,试试添加 -Wextra。)

关于c++ - 如果包含 "-ansi"编译器选项,为什么我的 C++0x 代码无法编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5861729/

相关文章:

具有继承性的 C++ 构建器模式

c++ - 收到错误 clang : error: linker command failed with exit code 1 (use -v to see invocation) while compile C++ file from terminal

c++ - gcc 4.5.1 vs VC2010 模板部分特化 : which is C++0x conformant?

c++ - 生成文件 - 错误 : file truncated

c++ - 如何加快 std::vector 访问时间

c++ - 为什么 C++ ofstream write() 方法会修改我的原始数据?

C++11、shared_ptr.reset() 和循环引用

c++ - 用 g++ 编译 C++11

python - 未检测到 theano g++,但我已成功安装 g++

c++ - 如何在 Qt 4.8 Issues Tab 中显示 C++ 的所有警告?