I am on C++
using std::vector
to store a list of class objects using vector::push_back
.
My add function accepts the base class type so that the same method can be used across.
Add(MyBaseClass object) {
my_vector.push_back(object)
}
I have remove function to remove it by per item added
Remove(MyBaseClass object) {
my_vector.erase(std::remove(my_vector.begin(), my_vector.end(), object), my_vector.end());
}
The add works fine but my Remove method gives following error:
overload resolution selected deleted operator '=='
if (!(*__i == __value_))
~~~~ ^ ~~~~~~~~
I picked up the vector::erase code from here. What is wrong with my way of erasing an item? Are there any other preferable ways to erase by item?