I m试图在1-file .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;
}
我正在发现一个错误,如下文所示,我不敢肯定在我使用“如果在某类成员方法中发挥作用”时会出现什么情况。 我在这样做时会发现这一错误。
1>c:program filesmicrosoft visual studio 8vcincludealgorithm(87) : error C2064: term does not evaluate to a function taking 1 arguments 1> c:program filesmicrosoft visual studio 8vcincludealgorithm(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: estprogram omfcmain.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> ]