我有以下代碼:是否刪除它的字段的超類調用析構函數?
template<class T>
class List<T> {
class Node{
T data;
Node * next;
...
};
Node * head;
...
~List() {/*iterating through all nodes and deleting them*/}
...
};
template<class T>
class Tree<T> {
class Node {
Node * next;
...
T key;
List<int> internal_list;
};
destroy_node(Node * x) { delete x; }
};
是否destroy_node(Node * x)
調用List<T>
類的析構函數或者我需要顯式調用呢?
這有點令人困惑,因爲你有兩次Node作爲嵌套類。刪除Tree :: Node將調用Tree :: Node :: internal_list的析構函數 – 2014-10-31 20:49:21