Re: using TR1 <functional> in a very simple case
On Nov 16, 8:59 am, Piotr Dobrogost <google...@2008.autoera.pl> wrote:
I use a library which needs function with signature R f(T1, T2, T3) as
a callback.
I made my class which has a public member function with this
signature.
How can I bind this method with a given instance of this class and
register it as a callback using TR1 functions and templates from
<functional>?
To bind a (non-static) class member function to a std::tr1::function
object, the function signature used to instantiate the function object
must specify (as its first parameter) a pointer to an object of the
appropriate class.
For example, given a class "C" with a member function of the form:
R f(T1, T2, T3)
then a matching std::tr1::function object would have to be
instantiated with this function type:
R f(C*, T1, T2, T3)
(To match a const member function, pass a pointer to a const class
object as the first parameter).
Need the interface of the library be changed in this case?
Yes, assuming that the implementation of the member callback fuction
actually needs an implicit "this" pointer to a class object.
Otherwise, the member function could simply be declared "static" - in
which case, there would be no adjustment made to the function type
used to instantiated the std::tr1::function object.
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]