Implementing callback using template functors in C++

Dear Developers,

Can you please explain me how can I implement callback function using template functors in C++.

I have read following article on this topic by Rich Hickey, but could not understand how can I use it in my application.

http://www.tutok.sk/fastgl/callback.html

I have basic knowledge of functors and templates, and have already used it in my application. But unfortunately could not understand everything on above mentioned article.

It would be great if someone will explain me by giving real time example.

Many thanks
1. I deleted your other 2 copies of the same post you scattered over this forum.
http://www.catb.org/esr/faqs/smart-questions.html#forum

If you've also posted this on other forums as well, then you've just annoyed a lot of people.
Do everyone a favour and post links to those other forums. Then everyone involved isn't going to waste time explaining the obvious over and over.

2. That article is 6000+ words.
No one here is going to post real examples for every point brought up by that article based solely on your vague "I'm confused" plea.

Make a prototype code which shows us the limits of your understanding, and ask a specific question about what it is you're trying to achieve.
As a side note, that article predates the standardization of C++. I would not recommend it as a learning resource for modern C++. Still, I skimmed through it, and it seems to discuss the implementation of a class template that essentially wraps a function pointer. They also seem to have a way to handle binding data to parameters.

This is not something you'll need to write in practice, and if you do, not as described in that article. C++ has had std::function for a while now, which does something similar but is much, much more flexible: http://www.cplusplus.com/reference/functional/function/function/#example

That being said! If you're familiar with class templates and familiar with functors, then templated functors aren't significantly more complex, conceptually. Try writing a normal functor for some predetermined types, then changing it to a template.

-Albatross
Topic archived. No new replies allowed.