【发布时间】:2016-10-21 06:44:32
【问题描述】:
我们可以将 [] 运算符或 ++ 与唯一指针或 shared_pointer 一起使用吗?当我们将它用于原始指针时
int * a = new int[10];
a[0] = 2; // We can use [] operator;
智能指针有类似的方法吗?
如果有的话应该什么时候用这个?
- 如果不存在那为什么?
- 多维数组也可以吗?
【问题讨论】:
-
cplusplus.com/reference/memory/unique_ptr 对
shared_ptr做同样的事情 -
您可以在数组上使用 shared_pointer :
std::shared_ptr<std::array<int, 10>>
标签: c++ arrays pointers smart-pointers