Will deleting a structure's pointer also delete pointers within the structure?

c++, delete-operator, destructor, struct

Solution

Not unless your destructor `~Listnode` calls `delete` on the pointers. Calling `delete` will, however, invoke the destructors of non-pointer members.

Problem

Assume I have a structure with two pointers each pointing to an object that has an implemented destructor. Also assume that the head points to a Listnode structure that has a non-NULL value *student and *next: ``` struct Listnode { Student *student; Listnode *next; }; Listnode *head = new Listnode; ``` If I use the `delete` reserve word on the Listnode pointer 'head' will it call the destructors within that structures Student class and Listnode class which 'student' and 'next' point-to respectively. In other words, will deleting *head also delete *student and *next provided head was the only pointer to that Listnode

Original source