Why the following code does not compile? If I change the function
argument to value (not reference) everything is ok. Is it possible to
modify such code that it will compile with reference argument type?
Best regards
Dominik
#include <string>
#include <list>
#include <algorithm>
struct Data {
void f(const std::string& str) { }
};
void main() {
std::list<Data> l;
std::for_each(l.begin(), l.end(),
std::bind2nd(std::mem_fun_ref(&Data::f), "Test"));
}
And error message:
see reference to class template instantiation 'std::binder2nd<_Fn2>'
being compiled
with
[
_Fn2=std::mem_fun1_ref_t<void,Data,const std::string &>
]
error C2529: '_Right' : reference to reference is illegal