std::unique_ptr支持数组,例如: std::unique_ptr<int[]> p(new int[10]); 但是这真的需要吗?可能使用 std::vector 或 std::array 更方便。 你认为这个结构有什么用处吗?
这个程序有什么问题?#include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); s...
好的,上一次我写C++还在从事工作,std::auto_ptr是所有 std lib 中可用的东西,boost::shared_ptr是当时最流行的。我从来没有真正研究过 boost 提供的其他智能指针类型。我了解到 C++11 现在提供了一些 boost 开发的类型,但并非所有类型都有。 ...
以下指针的区别是什么?在生产代码中何时使用每个指针(如果有)?欢迎提供示例! scoped_ptr shared_ptr weak_ptr intrusive_ptr 您是否在生产代码中使用boost?
我一直在查阅Clang源代码,我找到了这个片段: void CompilerInstance::setInvocation( std::shared_ptr<CompilerInvocation> Value) { Invocation = std::move(Val...
新标准的推出(某些编译器中已有部分功能),新类型std::unique_ptr被认为是替代std::auto_ptr的一种选择。 它们的使用是否完全重叠(因此我可以在代码中进行全局搜索/替换(尽管我不会这样做,但如果我这样做了呢)),或者我应该注意一些从文档中无法看出的差异? 另外,如果它...
你能让一个std::shared_ptr指向一个数组吗?例如, std::shared_ptr<int> sp(new int[10]); 如果不行,那为什么呢?我已经意识到的一个原因是无法对std::shared_ptr进行递增/递减操作。因此,它不能像普通指向数组的指针一...
std::make_unique是否像std::make_shared一样有任何效率优势? 与手动构造std::unique_ptr相比:std::make_unique<int>(1); // vs std::unique_ptr<int>(new ...