重複の可能性:
関数からunique_ptrを返す
20.7.1.2 [unique.ptr.single]は、次のようなコピーコンストラクターを定義します。
// disable copy from lvalue
unique_ptr(const unique_ptr&) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
では、なぜ次のコードが正常にコンパイルされるのでしょうか。
#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;
}
私はそれをこのようにコンパイルしました:
g++ -O3 -Wall -Wextra -pedantic -std=c++0x kel.cpp
コンパイラ:g++バージョン4.6.110110908(Red Hat 4.6.1-9)