Using find_if on a vector of object

Viewed 89521

I have a vector of that looks like the following:

class Foo
{
    //whatever
};

class MyClass
{
    int myInt;
    vector<Foo> foo_v;
};

And let's say, in the main:

int main (void)
{
    vector<MyClass> myClass_v;
}

I want to find a object in myClass_v that has myInt == bar. I don't care about foo_v. I thought of using the std::find_if function:

std::find_if(myClass_v.begin(),myClass_v.end(),condition);

with

bool MyClass::condition(MyClass mc)
{
    if(mc.myInt==5)
        return true;
    else
        return false;
}

However the compiler says that condition() is missing arguments. Could you tell me what am I doing wrong? I thought that std::find_if would call condition(*First), with First being a pointer to a myClass object.

Or is there another good way to do the same thing?

4 Answers
Related