【发布时间】:2013-12-25 18:01:05
【问题描述】:
我有这个:
struct Node;
typedef boost::intrusive_ptr<Node> NodeSPtr;
...
boost::scoped_array<NodeSPtr> nodes(new NodeSPtr[size]);
...
// "pollute" operations ...
...
// reset all the items in the array
for (size_t i = 0; i < size; ++i)
nodes[i].reset();
什么是初始化数组的最干净、更 STLish 的方法。请注意,代码对性能敏感,不能选择使用向量。
【问题讨论】:
-
我不完全确定你想要什么。您似乎只想重置
scoped_array。boost::scoped_array中有一个Reset()函数。 -
scoped_array 重置会释放数组中的所有项目,但不会重置它们
标签: c++ boost stl scoped-ptr