[Solved] class destructor segmentation fault


Your pop function destroys the entire stack. It deletes the tmp node (by calling the Stack destructor), which still points to the new next.
And since the Stack destructor calls delete on next, you get a mess of multiple destructor calls on the same objects.

JMA beat me to it by a few seconds, so refer to their code fix for a quick solution.

However, I would recommend you add a dedicated Node struct instead of composing Stacks, it will actually increase the clarity of your code.

3

solved class destructor segmentation fault