I have posted the code below, it is an assignment for class I am supposed to have working. He updated the code, and when I tried to follow it, I found that I can go INSIDE the member functions, but it has some type of exception error, and it never outputs the array. Could someone help me to find out why that is? I would love help a lot
EDIT: It is the remove and search function that seems to have the Error. I go into REMOVE, then SEARCH, then REMOVE, then SEARCH, then it crashes.
EDIT2: I commented out the line delete &DB[count2]; and now the code compiles for me, but it will not print out the array at all. It should print it out a lot, but it never does.
Yes you should show where you have defined DB. The way you are deleting it makes me think it is allocated on the stack and you can't manually deallocate memory on the stack.
To remove an element from an array, you have 2 options:
- Create a new array of size - 1 and copy everything (except for item to be removed) to this array
- Manually shift everything (starting from the position after the item to be removed) one space to the left
- If order doesn't matter, simply swap the last item in the array with the item you want to remove
For me it can compile as long as I // out the parts that involve .Remove in the main.
But when it involved .Remove it doesnt work.
I tried to comment out each line in Operator+ but I do not recieve that error. I will try to double check Search, and see what is wrong there.
I am not sure how to go about removing 1 piece of a dynamic array and shifting the entire array to the left 1. I tried to google it, and I saw something similar I thought, so I tried that.