Change your destructor to print on the outside of the if
statement.
The destructor is being called, however, on your last node next
is NULL
, so the if
statement returns false
and the cout line is not being called.
virtual ~Node()
{
cout << "Node is out: " << data << endl;
if (next != NULL)
{
delete next;
}
}