Need help in 'remove' function to a dynamic array

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.
Last edited on
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
I will be recovering help
Last edited on
Search and Remove seems to be the issue I am having with this code. Could someone please tell me the issue with it?
This code doesn't even compile...

But, if I remove the offending line in operator+ then I am presented with a warning:

warning C4715: 'TLIST<char>::Search' : not all control paths return a value


And, since you say you suspect the problem may reside in Search, perhaps you should go about fixing that.

Also delete &DB[count2]; in Remove is most certainly wrong.
Last edited on
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.
Last edited on
Well I deleted the line delete &DB[count2]; and the code ran, however, it does not print out the dynamic array of chars at all.
Topic archived. No new replies allowed.