Function pointers are very handy in C++. But they don't work on class methods, here is a neat workaround, that even works with virtual methods.
  1. Mr. Wonko (2011-12-07 19:22)

    Class method pointers… Nothing special really, how’s that a hack? Useful, of course, and good to know, but a hack? That’s more like overloading the comma or something. And wouldn’t a simpler example suffice?

    And why do you use new here? You gain nothing but have to remember to call delete (which you don’t), or do you?

    Man, I always seem overly critical… Sorry about that. I’m really just trying to help. Anyway, some simpler code showcasing class method pointers:

  2. Joe (2011-12-07 19:38)

    @Mr.Wonko: Thanks for your example, but code doesn’t work well with in the comments of my wordpress blog. I cleaned up the example source a little bit (I just copied, pasted and edited it on the fly from a current project I’m working on).

  3. Mr. Wonko (2011-12-07 19:48)

    Yeah, the example’s much better now. Good luck with your current project. :)

  4. Urfoex (2011-12-08 09:04)

    New function objects are looking better I think:

    Old school the using variant looks also kind of neat:

Add your comment now