Я пытаюсь встроить следующий блок кода в 1-файл .cpp файл:
#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;
}
Я получаю сообщение об ошибке, как показано ниже, и я не совсем уверен, что происходит, когда я использую функцию find_if в методе члена класса, и я получаю эту ошибку всякий раз, когда я делаю это.
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> ]