Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:37:45+00:00 2026-05-23T17:37:45+00:00

I have a vector of that looks like the following: class Foo { //whatever

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:37:45+00:00Added an answer on May 23, 2026 at 5:37 pm

    That’s not how predicates work. You have to supply either a free function bool Comparator(const MyClass & m) { ... }, or build a function object, a class that overloads operator():

    struct MyClassComp
    {
      explicit MyClassComp(int i) n(i) { }
      inline bool operator()(const MyClass & m) const { return m.myInt == n; }
    private:
      int n;
    };
    
    std::find_if(v.begin(), v.end(), MyClassComp(5));
    

    In C++0x:

    std::find_if(v.begin(), v.end(),
                 [](const MyClass & m) -> bool { return m.myInt == 5; });
    

    This captureless lambda is in fact equivalent to a free function. Here is a capturing version that mimics the predicate object:

    const int n = find_me();
    std::find_if(v.begin(), v.end(),
                 [n](const MyClass & m) -> bool { return m.myInt == n; });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that looks like this: typedef std::list<char*> PtrList; class Foo {
I have the following data that looks like this for example: 34 foo 34
I have a vector in R that looks like this: dat <- c(TRUE, TRUE,
I have a vector, v3, that looks like this: v3 <- matrix(c(1,1,3,3,2,2, 2,3,1,2,3,1, 3,2,2,1,1,3),
I have a large nested vector that look like this: import Data.Vector let x
I have the following code: void Foo() { static std::vector<int>(3); // Vector object is
I have the following in my Puzzle.h class Puzzle { private: vector<int> puzzle; public:
I have a vector that looks like this: mass<-c(-2, -6, -79, 31, -28, 198,
I have some data that looks like the following. It is grouped by variable
I have an std::vector -like class that is compiled with Visual C++ 2008. There's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.