c++ programming help
Go to solution
Solved by Mira Yurizaki,
Leave the destructor empty.
The reason is the array int x[5] = {0,1,2,3,4}; is only alive within the scope of exercise1. Once the function returns, it calls dataStorage's destructor, but since that array no longer exists and it's trying to delete it, the destructor is trying to do things to a memory location it doesn't own (and it probably never owned it anyway). You only need to delete things if the object created any new data in the heap (i.e., invoking the new keyword).
There's also some other errors but I won't point them out. That's an exercise for you to fix.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now