SFML community forums
Help => System => Topic started by: fatum 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:
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!
-
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:
template <typename C>
Thread(void (C::*function)(), C* object)
See here (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Thread.php). Then you have to pass &Test::ThreadHandle and this as arguments.
-
I have :
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 )
-
Are you using SFML 1.6?
-
yes sir , im using 1.6
will 2.0 work fine ?
-
The syntax that you use is for SFML 2.0 only. Read the documentation and tutorials ;)