【发布时间】:2012-03-22 17:14:51
【问题描述】:
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++ version 4.6.1 20110908 (Red Hat 4.6.1-9)
【问题讨论】:
-
+1 实际告诉我们您使用的是什么编译器以及如何编译代码。 StackOverflow 上的罕见景象。
标签: c++ g++ c++11 unique-ptr