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

标签 c++ c++11 unique-ptr

假设我有以下内容:

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/

相关文章:

c++ - 在 Windows 中以编程方式调用 "main"函数

c++ - Eclipse 索引器无法解析 shared_ptr

c++ - 为什么 std::unique_ptr 比标准指针慢得多……在优化之前?

c++ - 在unique_ptr <>中使用自定义删除器(curl_formfree())

c++ - 如何从 Rust 调用 C++ 动态库?

c++ - QT Creator 没有自动检测 MSVC2017 64 位编译器

c++ - 使用参数包将 lambda 转换为 std::function

c++ - 很多非类型模板参数

c++ - 对象 union 与指针 union

c++ - 对 Windows HANDLE 使用 std::unique_ptr