Warum kann ich ein unique_ptr nicht von einem Paar zurückgeben?Warum kann ich ein unique_ptr nicht von einem Paar zurückgeben?
#include <iostream>
#include <memory>
#include <utility>
using namespace std;
unique_ptr<int> get_value() {
pair<unique_ptr<int>, int> p(unique_ptr<int>(new int(3)), 4);
return p.first;
}
int main(void) {
cout << *get_value() << endl;
return 0;
}
Wenn ich versuche, dies mit g ++ zu kompilieren 4.6, erhalte ich:
../main.cpp: In function ‘std::unique_ptr<int> get_value()’:
../main.cpp:9:11: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int, _Dp = std::default_delete<int>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<int>]’
/usr/include/c++/4.6/bits/unique_ptr.h:256:7: error: declared here
make: *** [main.o] Error 1
Ich verstehe nicht, die Fehlermeldung
'std :: unique_ptr' ist Nur-Verschieben. – chris
wie ist das nicht nur für bewegungen? – dspyz