I am trying to pass a class internal function as a callback function within the class. The error behavior is similar to this problem this problem. Whatsoever, I was unable to construct working code based on that question's answer.
I am trying to pass a class internal function as a callback function within the class. The error behavior is similar to this problem. Whatsoever, I was unable to construct working code based on that question's answer.
I am trying to pass a class internal function as a callback function within the class. The error behavior is similar to this problem. Whatsoever, I was unable to construct working code based on that question's answer.
fun times with polymorphism this
This is whatcode we discussed during looking for a solution. I tried till nowleave it here for future reference.
I also tried creating an instance of this wrapper within the actual class to hold the callback, but that did not work either. Sorry I am a bit cumbersome with C++, coming from another language and apparently bit off a bit more than I could chew...
fun times with polymorphism this is what I tried till now. I also tried creating an instance of this wrapper within the actual class to hold the callback, but that did not work either. Sorry I am a bit cumbersome with C++, coming from another language and apparently bit off a bit more than I could chew...
fun times with polymorphism
This is code we discussed during looking for a solution. I leave it here for future reference.
I tried creating an instance of this wrapper within the actual class to hold the callback, but that did not work either.
For discussion with Michail
class CallbackWrapper
{
public:
void (*myCallback)();
void call()
{ myCallback(); }
virtual void setCallback(void (*callback)())
{ }
};
class MyClass : public CallbackWrapper
{
public:
void setCallback(void (*callback)())
{ myCallback = callback; }
void do_this() { Serial.println("doing this"); }
void do_that() { Serial.println("doing that"); }
void call()
{
CallbackWrapper::call();
if (rand() > 0.5)
{ setCallback(&MyClass::do_this); }
else
{ setCallback(&MyClass::do_that); }
}
MyClass()
{ }
};
For discussion with Michail
class CallbackWrapper
{
public:
void (*myCallback)();
void call()
{ myCallback(); }
virtual void setCallback(void (*callback)())
{ }
};
class MyClass : public CallbackWrapper
{
public:
void setCallback(void (*callback)())
{ myCallback = callback; }
void do_this() { Serial.println("doing this"); }
void do_that() { Serial.println("doing that"); }
void call()
{
CallbackWrapper::call();
if (rand() > 0.5)
{ setCallback(&MyClass::do_this); }
else
{ setCallback(&MyClass::do_that); }
}
MyClass()
{ }
};
- 143
- 1
- 7