SFML community forums

Help => System => Topic started by: Howitzer21 on February 15, 2012, 02:00:41 am

Title: How to use threads with class member functions.
Post by: Howitzer21 on February 15, 2012, 02:00:41 am
How do you use threads with class member functions?  If I pass a function pointer to a global function to a new Thread object, that works fine.  If I try to pass a function pointer to a member function inside of a class, that doesn't work out too well.  What's the syntax for it?  Thanks!
Title: How to use threads with class member functions.
Post by: Laurent on February 15, 2012, 08:04:27 am
SFML 1.6 or 2?
Title: How to use threads with class member functions.
Post by: Howitzer21 on February 15, 2012, 04:52:19 pm
1.6
Title: How to use threads with class member functions.
Post by: Laurent on February 15, 2012, 05:19:34 pm
Ok. So just read the tutorial please ;)
Title: How to use threads with class member functions.
Post by: Howitzer21 on February 15, 2012, 05:29:26 pm
I DID read the tutorial.  I practiced it and everything.  There was stuff in there for using them with function pointers to globally-defined functions, as well as inheriting a class from them.  But as for not using inheritance and just passing a function pointer to a class function, there's really no reference there.  I've tried it myself and haven't been able to get it to wrok.
Title: How to use threads with class member functions.
Post by: Howitzer21 on February 15, 2012, 05:34:45 pm
Well, I did manage to get it working with static functions, but what if I want to use a function specifically associated with that object without having the class inherit from Thread?  Is there a way to do this?
Title: How to use threads with class member functions.
Post by: Nexus on February 15, 2012, 05:37:44 pm
Quote from: "Howitzer21"
But as for not using inheritance and just passing a function pointer to a class function, there's really no reference there.
Because there is no possibility. Function pointers and member function pointers are not compatible to each other.

If I remember the old API correctly, you can use the void* to call indirectly a class member function. But you'd probably better use SFML 2.
Title: How to use threads with class member functions.
Post by: Howitzer21 on February 15, 2012, 05:43:31 pm
Thanks, Nexus!