1.4 .3 error when binding two arguments of the member function

Yuxin Liu

Active Member
C++ Student
For exercise 3, when I try to bind the member function translate2, f3 = bind(&C::translate2, &c, placeholders::_1, 2.0); works fine, but f3 = bind(&C::translate2, &c, placeholders::_1, placeholders::_2); will generate the error "Error C2679 binary '=': no operator found which takes a right-hand operand of type 'std::_Binder<std::_Unforced,double (__thiscall C::* )(double,double),C *,const std::_Ph<1> &,const std::_Ph<2> &>' (or there is no acceptable conversion) ".

Should we avoid using placeholders for all the arguments in a function?

Thank you in advance!
 

GONG CHEN

Well-Known Member
C++ Student
It's possible. The error indicates the return type of std::bind does not match the type of f3 -- there are 2 placeholders in your second example, but FunctionType is declared as "std::function<T (const T& t)>;"
 

Yuxin Liu

Active Member
C++ Student
It's possible. The error indicates the return type of std::bind does not match the type of f3 -- there are 2 placeholders in your second example, but FunctionType is declared as "std::function<T (const T& t)>;"
Oh silly me...Thank you so much!
 
Top