question regarging callback functions
-
why should a call back function be static when its called from an another class? say we have a class A and class B assume that class A calls a function in B say "b" and passes the address of an another function in A say "a". then to get get this working why is it a must that the function "a" be static.....we are passing the address of the member function as whole rt?..... :confused:
-
why should a call back function be static when its called from an another class? say we have a class A and class B assume that class A calls a function in B say "b" and passes the address of an another function in A say "a". then to get get this working why is it a must that the function "a" be static.....we are passing the address of the member function as whole rt?..... :confused:
namaskaaram wrote:
why should a call back function be static when its called from an another class?
It is not only when it has to be called from another class: it is whenever your callback function is a member function of a class. The difference between static member functions and non-static member functions is that for the non-static one, there is an implicit parameter that is passed to the function: the address of the instance of your class (the this pointer). As static member functions are shared across all instances of your class (and thus don't belong to a particular instance, thus cannot access non-static data from one instance), there is no implicit 'this' parameter that is passed. This of course change the prototype of the callback function (because of the implicit parameter), that's why static and non-static member functions behave differently.
Cédric Moonen Software developer
Charting control