我遇到了一个非常奇怪的错误,如果我使用的话只会弹出 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
。)
std::shared_ptr
在c ++ 98中不存在。尝试这些更改:
#include <tr1/memory>
...
explicit Test(std::tr1::shared_ptr<double> ptr) {}
嗯,因为C ++ 0x还没有ANSI标准? ANSI标志检查是否符合现有标准,而不是未来标准。