我試圖建立下面的代碼塊在1文件.cpp文件:find_if功能建設問題
#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> ]
若要創建代碼塊,請縮進4個空格,或按下1和0的按鈕 – 2009-05-27 00:21:22