callbacks and static member functions
you can not use non-static member functions as callback.
because class member functions have a hidden argument i.e. this pointer
pointing to the object.while for callbacks you need to have a function with exact declaration/signature.So you can't pass 'this' in the callback.
On the other hand Static member functions do not have this pointer as they can be called without making an instance of class.
So if you want to use a CLASS MEMBER FUNCTION for callback.It must be declared as static.
Also static declaration is given inside class definition only,while define the function in cpp you don't give the keyword 'static'.
because class member functions have a hidden argument i.e. this pointer
pointing to the object.while for callbacks you need to have a function with exact declaration/signature.So you can't pass 'this' in the callback.
On the other hand Static member functions do not have this pointer as they can be called without making an instance of class.
So if you want to use a CLASS MEMBER FUNCTION for callback.It must be declared as static.
Also static declaration is given inside class definition only,while define the function in cpp you don't give the keyword 'static'.

0 Comments:
Post a Comment
<< Home