【发布时间】:2014-07-16 11:31:26
【问题描述】:
有没有一种优雅的方式来升级到使用 boost 的 scoped_ptr 或 scoped_array 截断的以下代码?
MyClass** dataPtr = NULL;
dataPtr = new MyClass*[num];
memset(dataPtr, 0, sizeof(MyClass*));
allocateData(dataPtr); // allocates objects under all the pointers
// have fun with the data objects
// now I'm bored and want to get rid of them
for(uint i = 0; i < num; ++i)
delete dataPtr[i];
delete[] dataPtr;
【问题讨论】:
-
可以修改 allocateData() 吗?
-
理论上我可以,但是由于很多旧代码都以这种方式使用这个函数,所以我很犹豫是否这样做,并且更喜欢一个不修改它的解决方案。
标签: boost double-pointer scoped-ptr