Im a CS student new to C++ as i used to use java, and well decided to google around to find something to remove an object from my vector (aka arraylist in java) at any given index.
i found it at here at (http://www.cplusplus.com/reference/stl/vector/)
which basically gave me the answer. So i implemented it in mine and this is how i wrote it...
N.B. this is for a project regarding the board game "Talisman" . Now each "Character" object has a vector of type "Objects".. this vector is basically their "belt" which is where they store their swords, armour, and magical object.
anyways here is my portion of the code:
void Character::takeObjectFrom(Character y, int i)
y.objects.erase(y.objects.begin() + i);
and it is being called in the driver/(main) as follows...
now for some reason, it does not remove the object from the character y array... is there a reason why? everything is exactly the same as i've seen on forums and they claim that it is working... everything works fine with push and pop, but that just acts like a stack, which is not what i want for here..
any ideas why this is not working?
note: the c does get the object at c's index, BUT c still holds that object when it should have been erased...
Any help would be appreciated thanks!