在这种情况下,unique_ptr的行为应该是什么?

Jes*_*ood 4 c++ unique-ptr c++11

说我有以下内容:

std::unique_ptr<A> pA;
pA(new A);
Run Code Online (Sandbox Code Playgroud)

在这个复杂的例子中,行为应该pA(new A);是什么?

据我所知,在MSVC2010中,void operator()(T*) const;new返回后立即调用default_delete 并立即删除指针.而g ++(4.7.0)给了我no match for call (std::unique_ptr<A>)(A*)错误.

Jam*_*lis 6

代码不应该编译. std::unique_ptr没有超载operator().

Visual C++ 2011 Developer Preview正确地拒绝了代码.Visual C++ 2010仅接受代码,因为std::unique_ptr实现中存在错误.