STL算法传递参数的问题
#include <iostream>
#include <vector>
using namespace std;
//为什么这里的参数不能够按引用传递?
bool Compare(const int a1,const int a2)
{
return a1 > a2;
}
int main()
{
vector<int> MyVec;
for (int i = 0;i < 10;++ i)
{
MyVec.push_back(i);
}
int num = count(MyVec.begin(),MyVec.end(),3);
num = count_if(MyVec.begin(),MyVec.end(),bind2nd(ptr_fun(Compare),3));
cout << num;
return 0;
}
[解决办法]
binder2nd(const _Fn2& _Func,
const typename _Fn2::second_argument_type& _Right)
用引用的话,就实例化为binder2nd(×××××,
const int&& _Right) 类型错误