
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... } But the compiler tells me: could not deduce template argument for 'overloaded function type' from 'overloaded function type' Do you have any idea, how to do this? Thanks in advance for your help. Regards, Jan ---------------------------------------------------------------------- Dipl.-Inform. Jan Ohlenburg Fraunhofer Institut fuer Angewandte Informationstechnik FIT Forschungsgruppe Collaborative Virtual and Augmented Environments Schloss Birlinghoven D - 53754 Sankt Augustin, Germany Telefon: +49-2241-14-2724 e-Fax: +49-2241-14-4-2724 Telefax: +49-2241-14-2084 e-mail: mailto:jan.ohlenburg@fit.fraunhofer.de

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 ) ...

Hi, thanks for your reply. I was not using boost:bind since I thought it must be bound to a pointer. The following line does the trick for me: boost::bind( &Object::setFieldImpl<T>, _1, fieldId, fieldData ); Regards, Jan ---------------------------------------------------------------------- Dipl.-Inform. Jan Ohlenburg Fraunhofer Institut fuer Angewandte Informationstechnik FIT Forschungsgruppe Collaborative Virtual and Augmented Environments Schloss Birlinghoven D - 53754 Sankt Augustin, Germany Telefon: +49-2241-14-2724 e-Fax: +49-2241-14-4-2724 Telefax: +49-2241-14-2084 e-mail: mailto:jan.ohlenburg@fit.fraunhofer.de
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Peter Dimov Sent: Wednesday, August 09, 2006 2:27 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] Question about boost::bind2nd
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 ) ...
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Jan Ohlenburg
-
Peter Dimov