
Jan Ohlenburg wrote:
Hi everybody, I would like to bind a member function within the template function using the template argument. Please have a look at the following code:
template<typename T> void Object::setField(FieldId fieldId, const T& fieldData) { // call for_each with setFieldImpl ... shadowCopies->for_each ( boost::bind2nd( boost::mem_fun(&Object::setFieldImpl<T>), fieldId, fieldData))); }
template<typename T> void Object::setFieldImpl(FieldId fieldId, const T& fieldData) { ... do some stuff... }
bind2nd is soo last century... have you tried using boost::bind? boost::bind( &Object::setFieldImpl<T>, fieldId, fieldData ) It is not guaranteed to work (MSVC 6 in particular might not be able to handle it), but it stands a better chance. If that fails, you'd probably need to use void (Object::*pmf)(FieldId, const T&) = &Object::setFieldImpl; ... boost::bind( pmf, fieldId, fieldData ) ...