Myślę, że to całkiem samo wyjaśniające - nie mogę korzystać z funkcji C++ 11, chociaż myślę, że mam wszystko ustawione poprawnie - co prawdopodobnie oznacza że nie.error: 'unique_ptr' nie jest członkiem 'std'
Oto mój kod:
#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;
}
Oto moja wersja g ++:
[email protected]:~/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.
Oto jak ja kompilacji kodu:
[email protected]:~/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
Zauważ, że próbowałam zarówno -std=c++11
i bezskutecznie.
Używam Ubuntu 12.04 LTS z dysku flash na komputerze Intel x64.
[odniesienie] (http: // pl .cppreference.com/w/cpp/memory/unique_ptr) mówi ci, który nagłówek musisz dołączyć. – juanchopanza