-
I'm trying to change the FadeInOut example. The
But this does not compile:
I really don't want to make my function static... is there a way to overcome this issue or is a limitation of the library? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Solved using a lambda:
Perhaps it can be documented somewhere. In real applications the features are organized in classes rather than putting everything outside. |
Beta Was this translation helpful? Give feedback.
-
@Mark-81 (moved to Discussions where it should have been asked first) The issue you ran into is a C++ language issue; it has very poor handling of callbacks and Some Background: I can't rely on the functional header to be present in Arduino which gives you The best solution:
C++ for the lambda captures the this pointer, and due this line of code (from your example above) is within the context of this class, it will call the member BlendAnimUpdate. |
Beta Was this translation helpful? Give feedback.
@Mark-81 (moved to Discussions where it should have been asked first)
The issue you ran into is a C++ language issue; it has very poor handling of callbacks and
this
capturing with function pointers. Later, lambdas were added to help. While your solution will work, a better one is listed below.Some Background:
This link discusses the C++ callback issue with member functions:
https://stackoverflow.com/questions/14189440/c-callback-using-class-member
I can't rely on the functional header to be present in Arduino which gives you
std::function
andstd::bind
. I found that many Arduino platforms didn't include it and the common std headers just didn't work with those platforms (probably why th…