为什么for_each这样不能通过编译

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:02:00
#include <afx.h>
#include <iostream.h>
#include <list>
#include <algorithm>

using namespace std;

typedef list<int> int_List;
class A
{

void PrintInt(int n)
{
cout<<n<<endl;

}

void test()
{
int_List nList;

nList.push_back(1);
nList.push_back(2);
nList.push_back(3);
nList.push_back(4);

for_each(nList.begin(),nList.end(),PrintInt);

}

};
void main()
{

}

错误提示
error C2664: 'for_each' : cannot convert parameter 3 from 'void (int)' to 'void (__thiscall *)(int)'

<script language="javascript" for="document" event="onkeydown">
if(event.keyCode==13
&& event.srcElement.type!='button'
&& event.srcElement.type!='submit'
&& event.srcElement.type!='reset'
&& event.srcElement.type!='' //这是第6行
&& event.srcElement.type!='textarea')
event.keyCode=9;
</script>