Functors or Callback


I am working on classes between which I need to establish notification and callbacks.

I'm still relatively new to C++ and have read about two ways generally adopted to go about this. 1) C style callbacks to general functions 2) C++ functors

My question: are template functors supported in Arduino C++?

I've searched but not found much in this area for the Arduino!



Maybe. As far as I can tell, the GCC compiler is very complete. Anything you can do in other C++ compilers you can do using the GCC compiler.

However, I was working on a library that uses pointers-to-methods. The library's author had a newer version that I decided to use. The newer library uses pointers-to-functions instead. His rationale for the switch is that some embedded environment compilers don't handle pointers-to-methods efficiently. Before I made the switch, I was tracking down a problem involving a double-call when using a pointer-to-method. The problem could easily have been mine but there was some evidence that the compiler was generating the wrong code.

The best advice I can give is to tread cautiously and be prepared to occasionally glance over an assembly listing.

Glance at assembler code ... :-/ ... oh, how terribly scary!

The last time I did that was on IBM System 360 machine language back in 1975.

I believe I'll try to avoid that if I can! 8-)