Removing an item from a vector

I am trying to write a method that removes an integer from a vector, but it gives me the following error.
use ‘&’ to create a pointer to member.
The method is:

1
2
3
4
5
6
  //TODO removes item from the bag; only one occurrence of item should be removed.
void Bag::remove(int item)
{
	bagOfMarbles.erase(bagOfMarbles.begin + item - 1), bagOfMarbles.end;
}


Did you read any documentation for that erase() member function?
http://www.cplusplus.com/reference/vector/vector/erase/

Do you realize that you're missing several parentheses?

Do you realize that .begin is a function, not a variable?

Are you trying to erase one or more than one item from your vector?


Do you realize that you're missing several parentheses?


Yes, it was a typo on my part but the parentheses go after the .begin and .end.

Do you realize that .begin is a function, not a variable?


Yes, I do understand that it is a function.

Are you trying to erase one or more than one item from your vector?


One item at a time, choose the number in the vector and erase it.

This is the general idea:
1
2
3
4
        std::cout << "There are " << B.count(4) << " fours";
	std::cout << "There are " << B.count(5) << " fives";
	B.remove(4);
	std::cout << "There are " << B.count(4) << " fours";
If you still have problems, post your modified code.

Last edited on
Topic archived. No new replies allowed.