Is it possible to do something like this:
int *iarray = new int[10];
.....
//do something with it
.....
and then in order to easily remove first element do this:
delete iarray;
iarray++;
it seems that delete (without [] ) still deletes whole array. If it's possible it would be really tricky and clever way to remove first element. The idea is not mine, I saw it somewhere, but it's doesn't work with me. Am I doing something wrong?
Use a deque to remove an element from the front — that's what this structure is invented for.
It looks like you're writing C++, in which case the delete
trick is madness and terrible and not going to work. You could certainly just get a pointer to the second element if that's what you really need by doing pointer math, but to actually remove the first item you're going to have to move everything back by one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With