只有一个关于shared_ptr
的小问题。
使用shared_ptr
指向数组是一种好的做法吗?例如,
shared_ptr<int> sp(new int[10]);
若否,原因何在?我已经知道的一个原因是不能递增/递减shared_ptr
。因此,它不能像普通的数组指针一样使用。
发布于 2013-10-03 21:03:03
一种可能更简单的替代方案是shared_ptr<vector<int>>
。
https://stackoverflow.com/questions/13061979
复制相似问题