大家指点:《c++标准程序库》一书中,p126---p127中的疑问
函数:for_each(col1.begin(), col1.end(), PrintIntI())
其中,PrintInt()为访函数,一种类的对象
而书中说写出for_each的算法如下:
template<class Iterator, class Operation>
Operation for_each(Iterator act, Iterator end, Operation op)
{
while (act!=end){op(*act);++act;}
return op;
}
可见,for_each函数的第三参数为一种类的对象(访函数)
而后书中有:for_each函数可接受,一般函数为第三参数如:
void add10(int& elem){
elem += 10;
}
void f1(){
for_each(col1.begin(), col1.end(), add10)
}
请问,这是怎么回事呢??for_each的原码算法显示,它的第三参数不是一种类的对象吗,为何能接受一般函数为参数??????
请指教,,