I have encountered a list of errors when i was trying to execute this erase function to remove ‘2’ from my vector. I am not sure where is the problem. Help will be greatly appreciated!
STRUCT MyInt
struct MyInt
{
friend ostream &operator<<(ostream &printout, const MyInt &Qn)
{
printout<< Qn.value << endl;
return printout;
}
int value;
MyInt (int value) : value (value) {}
};
STRUCT MyStuff
struct MyStuff
{
std::vector<MyInt> values;
MyStuff () : values ()
{ }
};
MAIN
int main()
{
MyStuff mystuff1,mystuff2;
for (int x = 0; x < 5; ++x)
{
mystuff2.values.push_back (MyInt (x));
}
vector<MyInt>::iterator VITER;
mystuff2.values.push_back(10);
mystuff2.values.push_back(7);
//error points to the line below
mystuff2.values.erase(std::remove(mystuff2.values.begin(), mystuff2.values.end(), 2), mystuff2.values.end());
return 0;
}
Error Messages
stl_algo.h: In Function ‘_OutputIterator std::remove_copy(_InputInputIterator, _InputIterator, const_Tp&) [with_InputIterator = __gnu_cxx:__normal_iterator > >, OutputIterator = __ gnu_cxx::__normal iterator > >, Tp = int]’
No match for operator==’
Erorr messages showed the partciular line violated practically stl_algo.h’s lines
Line 1267, 1190, 327, 1263, 208, 212, 216, 220, 228, 232, 236
You need to overload the
==operator for classMyInt.For example: