bind2nd的问题
我有一个类
class Test: private Parent;
重写了接口
Test& Test::operator&=(const Test&)
和
friend Test operator&(const Test&,const Test&)
然后我要用STL算法
transform(v.begin(),v.end(),w.begin(), bind2nd(ptr_fun<const Test&,const Test&,Test>(operator&),something));
这个是不行的。如果我不加上ptr_fun的模板参数,因为存在operator&的重载,所以编译器是不能自动推导的。
好,现在我改用
transform(v.begin(),v.end(),w.begin(), bind2nd(mem_fun_ref(&Test::operator&=),something));
这样就是可以的。
似乎是因为bind2nd会自动给第一个参数再加上一次const&。但是我看了08年的gcc编译器新闻组里面一个讨论讲,编译器碰到模板中有
template <typename T>
fun(const T&)
当T=const int&时,会自动去掉多余的const 和&。谁能解释一下这个问题?谢谢!