I have 2 vectors
std::vector<MyObj> v;
std::vector<MyObj2> z;
The objects in the vectors both contain an int
that has an ID. I want to see if when looking through v
it has a matching id
in z
So I thought that I could use `std::find_if and a Lambda.
for (int i=0; i < _z.size(); i++)
{
MyObj2 _g = _z.at(i);
auto iter = std::find_if(v.begin(), v.end(), [this](MyObj o)
{
if (o.getID() == _g.getID())
{
std::cout << "we have a match" << std::endl;
}
else
{
std::cout << "we DO NOT have a match" << std::endl;
}
});
}
but I am getting an error that I dont understand.
43: Member function 'getID' not viable: 'this' argument has type 'const MyObj2', but function is not marked const
I dont understand what has to be marked const and why?
an I needing something like in my .hpp?:
MyObj2& operator= (const MyObj2&);
MyObj2& operator== (const MyObj2&);