I created a small example of the problem I encountered. I've been dealing with this problem for a few days. i have not found a solution yet. I want to work with multiple instances of the Cla1 class here. therefore, I cannot define static hap_object_init and read_Data functions. thank you in advance
callback.hap_object_init = hap_object_init; // how to bind this function
i want to instance cla1 but binding error like this:
callback.hap_object_init = hap_object_init; // how to bind this function // gives error like this -> "Reference to non-static member function must be called"
but if i set as static hap_object_init everythings ok but i don't want static. i want be able multiple istance this class..
class foo{
public:
return_type bar(parameters...);
}
//equivalent to
return_type bar(foo *this, parameters...);
that's the meaning of the error.
> I want to work with multiple instances of the Cla1 class here. therefore, I
> cannot define static hap_object_init and read_Data functions
that's the purpose of the argument
1 2 3 4
void* read_Data(void *arg){ //not a member function
Cla1 *obj = reinterpret_cast<Cla1*>(arg);
return obj->read_Data();
}
So how do you want to organize these multiple instances? There must be container for this objects.
You cannot bind a member function to a pointer that requires a free function when using raw pointers. However nothing stops you from wrapping the desired class objects in static functions. So you have an indirect call. Still you need to organize the objects...
> !!must be non-static!!
OK, so how are you supposed to 'magic' a this pointer out of thin air?
Read ne555's post again.
If you're making more than 1 instance of NameSpa1::Cla1 at once, then you hap_ things need to store some kind of array / vector / list of all the live instances, from which meaningful 'this' pointers can be reconstructed using the static method wrapper previously illustrated.