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

Author Topic: Callback a method inside of a class with sf::Thread?  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

fatum

  • Newbie
  • *
  • Posts: 47
    • MSN Messenger - bowsers7@hotmail.com
    • AOL Instant Messenger - therealblah569
    • View Profile
    • http://boards.psynetfm.com
Callback a method inside of a class with sf::Thread?
« on: October 16, 2011, 01:30:13 am »
I've tried many different scenarios, but I can't seem to figure out.  Here's a basic example if what I'd like to do:

Code: [Select]

class Test
{
private:
ThreadHandle();
//
public:
Test();
void setup();
//
};


void Test::setup()
{
sf::Thread TestThread(&ThreadHandle);
TestThread.Launch();
}


I've also tried setting up the "TestThread" object in the header file, but it alerts me that "ThreadHandle" is not a data type.

Thanks for any help!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Callback a method inside of a class with sf::Thread?
« Reply #1 on: October 16, 2011, 02:32:01 am »
What do you want to do? Is ThreadHandle a member function of Test? I ask because the return type is missing, and the term "handle" usually refers to objects, not functions.

For member functions, you can use the following constructor:
Code: [Select]
template <typename C>  
Thread(void (C::*function)(), C* object)

See here. Then you have to pass &Test::ThreadHandle and this as arguments.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Ectance

  • Newbie
  • *
  • Posts: 8
    • View Profile
Callback a method inside of a class with sf::Thread?
« Reply #2 on: November 09, 2011, 07:15:25 pm »
I have :

Code: [Select]

class A
{
   private :
      sf::Thread *thread;
      bool running;
      void loop();
   public :
      A();
      ~A();
      void Start();
      void Stop();
    };



A::A()
{
   thread = new sf::Thread(&A::loop,this); // <- here is the error
   running = false;
}



A::~A()
{
   Stop();
   sf::Sleep(1.0f);
   delete thread;
}



void A::Start()
{
   running = true;
   thread->Launch();
}



void A::Stop()
{
   running = false;
}



void A::loop()
{
   while(running)
      // do sth
}



I get this error :
error C2664: 'sf::Thread::Thread(sf::Thread::FuncType,void *)' : cannot convert parameter 1 from 'void (__thiscall A::* )(void)' to 'sf::Thread::FuncType'
1>          There is no context in which this conversion is possible


( MS VC++ 2010 xpress )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Callback a method inside of a class with sf::Thread?
« Reply #3 on: November 09, 2011, 08:13:28 pm »
Are you using SFML 1.6?
Laurent Gomila - SFML developer

Ectance

  • Newbie
  • *
  • Posts: 8
    • View Profile
Callback a method inside of a class with sf::Thread?
« Reply #4 on: November 09, 2011, 08:51:20 pm »
yes sir , im using 1.6
will 2.0 work fine ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Callback a method inside of a class with sf::Thread?
« Reply #5 on: November 09, 2011, 10:48:15 pm »
The syntax that you use is for SFML 2.0 only. Read the documentation and tutorials ;)
Laurent Gomila - SFML developer

 

anything