Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Thread and class  (Read 3535 times)

0 Members and 1 Guest are viewing this topic.

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::Thread and class
« on: December 13, 2010, 03:09:59 pm »
Hello, I know there are similar threads as this one, but none of them quite answer my question, or perhaps I am unable to comprehend the answer.

However my question is if it's possible to use a thread to run a member function of a class?

Something like this:

Code: [Select]

class A
{
    public:

        A() {
            sf::Thread Thr(&myFunction);
            Thr.Launch();
        }

    private:

        void myFunction()
        {
            // .... Do some stuff ... //
         }

};


Or is there perhaps other solutions?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Thread and class
« Reply #1 on: December 13, 2010, 03:38:29 pm »
In SFML 2 yes.

In SFML 1 you have to inherit from sf::Thread and call your function Run(). This is explained in the tutorial.
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::Thread and class
« Reply #2 on: December 13, 2010, 03:39:12 pm »
Yeah I'm using SFML 2..

Could you give me a hint about how to do?

I feel as if I've tried everything!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::Thread and class
« Reply #3 on: December 13, 2010, 04:04:19 pm »
Quote
I feel as if I've tried everything!

Don't try, simply read the doc, it's very well explained with code examples ;)
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::Thread and class
« Reply #4 on: December 13, 2010, 04:54:23 pm »
Aaah, there it is.. I totally missed those examples :)
Thanks :)