![](/img/trans.png)
[英]How do I tell the C++ compiler on a supercomputer that my R package requires C++0x?
[英]Why does my C++0x code fail to compile if I include the “-ansi” compiler option?
我遇到了一個非常奇怪的錯誤,只有在我使用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 標志檢查是否符合現有標准,而不是未來標准。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.