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

  • Home
  • SEARCH
  • 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 227683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:37:08+00:00 2026-05-11T19:37:08+00:00

I’m trying to build the following block of code in a 1-file .cpp file:

  • 0

I’m trying to build the following block of code in a 1-file .cpp file:

#include <iostream>

#include <algorithm>
using namespace std;

class test
{

public:

    int a[10];
    int index;

    test();
    ~test();
    bool equals(int p);
    void search();
};

test::test()
{
    int temp[10] = {4, 9, 5, 6, 9, 10, 9, 255, 60, 0};

    memcpy(a, temp, sizeof(temp));

    index = -1;
}

bool test::equals(int p)
{
    return p == 9;
}

void test::search()
{
    int* p = std::find_if(a, a+10, &test::equals);
    while (p != a+10)
    {
        cout<< *p;
        index = p - a;
        p = std::find_if(p+1, a+10, &test::equals);
    }
}

int main(int argc, char *argv[])
{
    test object;

    object.search();

    return 0;
}

I am getting an error as shown below, and I’m not sure exactly what’s happening when I use the find_if function in a member method of a class, and I’m getting this error whenever I am doing so.

1>c:\program files\microsoft visual studio 8\vc\include\algorithm(87) : error C2064: term does not evaluate to a function taking 1 arguments
1>        c:\program files\microsoft visual studio 8\vc\include\algorithm(96) : see reference to function template instantiation '_InIt std::_Find_if(_InIt,_InIt,_Pr)' being compiled
1>        with
1>        [
1>            _InIt=int *,
1>            _Pr=bool (__thiscall test::* )(int)
1>        ]
1>        c:\testprogram\nomfc\main.cpp(32) : see reference to function template instantiation '_InIt std::find_if(_InIt,_InIt,_Pr)' being compiled
1>        with
1>        [
1>            _InIt=int *,
1>            _Pr=bool (__thiscall test::* )(int)
1>        ]
  • 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-11T19:37:09+00:00Added an answer on May 11, 2026 at 7:37 pm

    The find_if function expects an object which is callable as a function with no parameters. This is something like a free function, a function object or a static class function. You passed in the address of the equals member function which is none of these. You could resolve this by making the equals function a free function or a static function, since it does not require any members of the test instance.

    // static
    class test
    {
      public:
        static bool equals(int p); // etc
    };
    int* p = std::find_if(a, a+10, &test::equals);
    
    // free
    bool equals(int p)
    {
        return p == 9;
    }
    int* p = std::find_if(a, a+10, equals);
    

    If your real code example requires that it be a member function, then you need to pass in a function object that acts as a closure over the class instance. I favour using the Boost bind method for this, but there are other methods as well.

    int* p = std::find_if(a, a+10, boost::bind(&test::equals, this, _1));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.