Skip to content

Callback function as class member #576

Answered by Makuna
ghost asked this question in Q&A
Discussion options

You must be logged in to vote

@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 and std::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…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Makuna
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #575 on June 04, 2022 16:42.