我有一堂课
class A {
public:
A(){cout<<"C";}
~A(){cout<<"D";}
};
int main(){
unique_ptr<A> a(new A[5]); // - doesn't work
unique_ptr<A> a(new A[1]); // - doesn't work
unique_ptr<A> a(new A); // - works
}
为什么会这样?
我想这与移动构造函数有关(由于析构函数无法自动创建),但是为什么我们需要一个移动构造函数呢?
和有什么区别:
unique_ptr<A> a(new A[1]); // - doesn't work
unique_ptr<A> a(new A); // -works