//Invocation of this from outside of class will work fine
myObjectInstance.setEventCallback(1,someVoidFunction);
//To provide a default handler inside the library a call will lead to an <unresolved overloaded function type> exception
myObjectInstance.setEventCallback(1,SmartHouse::someVoidFunctionInsideTheClass);
I do understand the issue which is very well described here The Function Pointer Tutorials - Callbacks
Converting the function to a static function isn't possible as the callback needs to access non static fields.
As far as I understood another possibility is to pass a pointer (this) of my class instance to the function, but this would result in the need to change the function definition of callback to include a reference. Is this a correct assumption and is there another way to solve this issue? Changing the signature for every other function seems like a bad idea as this would result in a much worse usage of the library. Can we do some function overloading here to resolve everything?
Disclaimer: I am a greenhorn when it comes to C++ so go ahead and throw all the patterns and best practices at me.
BulldogLowell:
Which in the context of your function names, that makes particular sense, right?
Yes in this particular case it does make sense, but it was me who made a mistake with the minimal example as the default handler will access a field of the class which is non static therefore simply changing the function to be a static function does not work.
KilianB:
Yes in this particular case it does make sense, but it was me who made a mistake with the minimal example as the default handler will access a field of the class which is non static therefore simply changing the function to be a static function does not work.
hmmm... so in your example, someVoidFunction() accesses some object's member?
I'm having difficulty understanding what it is you are trying to do.