大家指点:《c++标准程序库》一书中,p126---p127中的疑问

littleroy littleroy 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
函数: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的原码算法显示,它的第三参数不是一种类的对象吗,为何能接受一般函数为参数??????
请指教,,






...全文
评论 3
收藏 已收藏
分享
返回顶部