2155得票14回答
313得票18回答
unique_ptr与数组有什么用途?

std::unique_ptr支持数组,例如: std::unique_ptr<int[]> p(new int[10]); 但是这真的需要吗?可能使用 std::vector 或 std::array 更方便。 你认为这个结构有什么用处吗?

285得票2回答
为什么我不能将unique_ptr push_back到vector中?

这个程序有什么问题?#include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); s...

244得票4回答
我应该在什么时候使用哪种指针?

好的,上一次我写C++还在从事工作,std::auto_ptr是所有 std lib 中可用的东西,boost::shared_ptr是当时最流行的。我从来没有真正研究过 boost 提供的其他智能指针类型。我了解到 C++11 现在提供了一些 boost 开发的类型,但并非所有类型都有。 ...

232得票4回答
智能指针(boost)解释说明

以下指针的区别是什么?在生产代码中何时使用每个指针(如果有)?欢迎提供示例! scoped_ptr shared_ptr weak_ptr intrusive_ptr 您是否在生产代码中使用boost?

217得票8回答
为什么我要使用std::move移动一个std::shared_ptr?

我一直在查阅Clang源代码,我找到了这个片段: void CompilerInstance::setInvocation( std::shared_ptr<CompilerInvocation> Value) { Invocation = std::move(Val...

215得票4回答
将std::auto_ptr转换为std::unique_ptr

新标准的推出(某些编译器中已有部分功能),新类型std::unique_ptr被认为是替代std::auto_ptr的一种选择。 它们的使用是否完全重叠(因此我可以在代码中进行全局搜索/替换(尽管我不会这样做,但如果我这样做了呢)),或者我应该注意一些从文档中无法看出的差异? 另外,如果它...

211得票6回答
C++中的RAII和智能指针

在C++实践中,RAII是什么?智能指针又是什么?如何在程序中实现它们,使用RAII和智能指针的好处是什么?

210得票2回答
你能让std::shared_ptr管理使用new T[]分配的数组吗?

你能让一个std::shared_ptr指向一个数组吗?例如, std::shared_ptr<int> sp(new int[10]); 如果不行,那为什么呢?我已经意识到的一个原因是无法对std::shared_ptr进行递增/递减操作。因此,它不能像普通指向数组的指针一...

195得票4回答
std::make_unique和使用new创建std::unique_ptr之间的区别

std::make_unique是否像std::make_shared一样有任何效率优势? 与手动构造std::unique_ptr相比:std::make_unique<int>(1); // vs std::unique_ptr<int>(new ...