假设我有以下内容:
std::unique_ptr<A> pA;
pA(new A);
在这个复杂的例子中,pA(new A);
的行为应该是怎样的?是吗?
据我所知,在 MSVC2010 中,void operator()(T*) const;
在 new
之后立即调用 from default_delete立即返回并删除指针。而 g++(4.7.0) 给了我 no match for call (std::unique_ptr<A>)(A*)
错误。
最佳答案
代码不应编译。 std::unique_ptr
不会重载 operator()
。
Visual C++ 2011 Developer Preview 正确地拒绝了代码。由于 a bug in its std::unique_ptr
implementation,Visual C++ 2010 只接受代码.
关于c++ - 在这种情况下 unique_ptr 的行为应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8468160/