Destructor of List cannot delete the last node
问题 Here is my test code: #include <iostream> #include <cstdlib> using namespace std; class List { private: class Node{ public: int data; Node* next; public: virtual ~Node() { if (next != NULL) { cout << "Node is out: " << data << endl; delete next; } } Node() { next = NULL; } }; Node* head; public: virtual ~List() { if (head != NULL) { delete head; } } List() { head = NULL; } public: void AddNode(int data); void DeleteNode(int data); //.... }; void List::AddNode(int data) { Node* temp = new Node