我想这很容易理解 - 尽管我认为我已经正确设置了一切,但似乎我无法使用 C++11 的功能,这很可能意味着我没有正确地设置。
以下是我的代码:
我在一台Intel x64机器上的闪存驱动器上运行Ubuntu 12.04 LTS。
以下是我的代码:
#include <cstdlib>
#include <iostream>
class Object {
private:
int value;
public:
Object(int val) {
value = val;
}
int get_val() {
return value;
}
void set_val(int val) {
value = val;
}
};
int main() {
Object *obj = new Object(3);
std::unique_ptr<Object> smart_obj(new Object(5));
std::cout << obj->get_val() << std::endl;
return 0;
}
这是我的g++版本:
ubuntu@ubuntu:~/Desktop$ g++ --version
g++ (Ubuntu/Linaro 4.7.3-2ubuntu1~12.04) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这是我编译代码的方式:
ubuntu@ubuntu:~/Desktop$ g++ main.cpp -o run --std=c++11
main.cpp: In function ‘int main()’:
main.cpp:25:2: error: ‘unique_ptr’ is not a member of ‘std’
main.cpp:25:24: error: expected primary-expression before ‘>’ token
main.cpp:25:49: error: ‘smart_obj’ was not declared in this scope
请注意,我尝试过-std=c++11
和-std=c++0x
,但均未成功。我在一台Intel x64机器上的闪存驱动器上运行Ubuntu 12.04 LTS。