Explore BrainMass
Share

C++ stack, Memory Problem

I have created my stack template (not using stl). my methods work for the testing file.

Even though the program runs correctly, there is a memory problem somewhere in the program and I can't figure out what I have done wrong. I have allocated new memory for my stack and I'm deleting it as well, but still there is a problem somewhere.

See the attachments.

© BrainMass Inc. brainmass.com July 18, 2018, 10:26 pm ad1c9bdddf

Attachments

Solution Preview

The error produced by this program is a little misleading. Various compilers will print out different messages but they will all say something similar to "possible corrupted stack". The "stack" being mentioned in this error message is NOT the stack class that is being implemented by the program. Instead, it is the heap used for memory allocation.

The Stack class constructor is correctly allocating a chunk of memory as an array. The destructor is correctly deleting that same ...

Solution Summary

This solution explains potential issues with an improperly-working stack template and proposes solutions for fixing those issues so that the programs will work properly.

$2.19