恐怕在這個領域的每個存在的問題/答案似乎是微妙的不同:如何爲shared_ptr的矢量投:: <T>迭代器(上堆)<T>
我有一個shared_ptr<vector<Point>> profile
它使用迭代器循環。我想爲了各種目的在循環外部保留一個shared_ptr<Point>
,但是我在語法上掙扎。請你指教?
這裏是一個基本的例子:
shared_ptr<Point> peak;
for (vector<Point>::iterator point=profile->begin(); point!=profile->end(); point++)
{
...
peak = shared_ptr<Point>(*point); // fails
...
}
N.B.我想使用一個簡單的參考/指針Point
會很簡單,但我試圖避免這種情況,尤其是涉及堆時。我也意識到,在這種情況下我可以使用索引,但這在容器類之間傳遞的可能性較小。
謝謝。請問shared_ptr不存在,直到向量本身超出範圍? –
mosi
2013-03-18 14:50:28
我不得不查看代碼的其餘部分以查看範圍。 – Nick 2013-03-18 15:56:20
好的,我會保重的。感謝您的建議。 – mosi 2013-03-19 12:03:23