如果我告诉您我无法编译此文件,我想这很尴尬。您能帮我吗:
#include<memory>
using namespace std;
int main()
{
std::unique_ptr<int> p1(new int(5));
return 0;
}
$ gcc main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:2: error: ‘unique_ptr’ was not declared in this scope
main.cpp:6:13: error: expected primary-expression before ‘int’
main.cpp:6:13: error: expected ‘;’ before ‘int’
$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
这只是一个猜测。
您最有可能像这样(或类似方式)编译程序:
g++ main.cpp
如果这样做了,那么问题在于g ++使用c ++ 03作为默认值。要使用c ++ 11功能(和std::unique_ptr
),您需要使用较新版本的c ++:
g++ -std=c++11
要么
g++ -std=c++14
我建议也使用-Wall -Wextra -pedantic
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句