为什么bind2nd(mem_fun_ref(&CLASS::Func),Para);CLASS::Func的参数不能是pass-by-(const)reference
//为什么bind2nd(mem_fun_ref(&CLASS::Func),Para);CLASS::Func的参数不能是pass-by-(const)reference
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
using namespace std;
class Test
{
public:
Test(int i){weight=i;}
bool Heavier(const int& k) const//pass-by-(const)reference
{return weight>k;}
int weight;
};
int main()
{
list<Test> TL;
for(int i=50;i<60;++i) TL.push_back(Test(i));
int w=55;
list<Test>::const_iterator F=find_if(TL.begin(),TL.end(),bind2nd(mem_fun_ref(&Test::Heavier),w));
if(F!=TL.end()) cout<<F->weight;
}
/*
BCB6和DEV-C++4都无法编译
如果把T::Heavier的参数从pass-by-(const)reference修改为pass-by-value就正确
bool Heavier(int k) const is OK!
很不解为什么pass-by-(const)reference就无法通过编译
如果无法解决,我只能pass-by-pointer了
*/