Olası Çoğalt:
Returning unique_ptr from functionsNeden unique_ptr'yi kopyalayabilirim?
20.7.1.2 [unique.ptr.single] tanımlar böyle yapıcı kopyalayın: Yani
// disable copy from lvalue
unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
, neden aşağıdaki kod derleme yapar ince?
#include <memory>
#include <iostream>
std::unique_ptr<int> bar()
{
std::unique_ptr<int> p(new int(4));
return p;
}
int main()
{
auto p = bar();
std::cout<<*p<<std::endl;
}
ben bunu böyle derlenmiş:
g++ -O3 -Wall -Wextra -pedantic -std=c++0x kel.cpp
derleyici: g ++ sürüm 4.6.1 20110908 (Red Hat 4.6.1-9)
+1. StackOverflow üzerinde nadir bir manzara. –
Bkz. Http://stackoverflow.com/questions/4316727/returning-unique-ptr-from-functions – Sjoerd