我有一個具有一個頂點成員的Polygon類。該成員是頂點鏈表的一部分,這些是頂點的頂點。所以,Polygon對象只包含一個頂點的一個引用,並且通過移動鏈表來獲取其他頂點。具有鏈接列表成員的對象的析構函數
問題是:銷燬多邊形對象。我來自C++,我在析構函數中做的是從多邊形的頂點開始,遍歷列表並刪除所有頂點。我應該在c#中做什麼?首先沒有刪除,並有自動垃圾收集,所以我不知道該怎麼辦。
這是C++析構函數解釋:
Polygon::~Polygon(void) {
if (_v) { // _v is Vertex member the Polygon has, the only one
Vertex *w = _v->cw();
while (w != _v) { // advance through the linked list members and delete them
delete w->remove();
w = _v->cw();
}
delete _v; // finally delete the vertex which is member of the polygon
}
謝謝
@Joey:你爲什麼把標籤改爲C++? – GManNickG