小编SJi*_*xin的帖子

通过引用或值传递函数?

#include <iostream>
#include <algorithm>
using namespace std;

bool myfn(int i, int j) { return i<j; }



int main () {
int myints[] = {3,7,2,5,6,4,9};

 // using function myfn as comp:
cout << "The smallest element is " << *min_element(myints,myints+7,myfn) << endl;
cout << "The largest element is " << *max_element(myints,myints+7,myfn) << endl;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

考虑到上面的代码,有什么不同,如果我们通过myfn&myfnmin_element?当我们试图传递一个更为标准的仿函数?

c++ stl

3
推荐指数
2
解决办法
303
查看次数

标签 统计

c++ ×1

stl ×1