1

I try to use a SFML Thread in my game, but I got a problem with it. My code:

void MyGame::endGame()
{
    sf::Thread thread(&PuzzleGame::endThread);
    thread.Launch();
}

void MyGame::endThread()
{

}

As a result I get:

../src/MyGame.cpp: In member function ‘void MyGame::endGame()’:
../src/MyGame.cpp:186:51: error: no matching function for call to ‘sf::Thread::Thread(void (MyGame::*)())’
sf::Thread thread(&MyGame::endThread);
                                    ^

What can be a problem?

EDIT I use SFML 1.6

2 Answers 2

1
thread.launch();

Note the lowercase.

Here's the docs in case you're interested:

http://www.sfml-dev.org/tutorials/2.0/system-thread.php

Sign up to request clarification or add additional context in comments.

1 Comment

Forgot to mention: I use SFML 1.6.
1

If you want to pass a class-function, you need to pass the object that you want to call it on, too:

void MyGame::endGame()
{
    sf::Thread thread(&MyGame::endThread, this);
    thread.launch();
}

void MyGame::endThread()
{

}

Alternatively you can use a static class method:

void MyGame::endGame()
{
    sf::Thread thread(&MyGame::endThread);
    thread.launch();
}

static void MyGame::endThread()
{

}

Please read the full documentation on SFML threads. Creating a local variable of a thread is not helpful. It will be destroyed when going out of scope and you want the thread to run, not to be deleted.

I see you are using the old SFML 1.6. Please read the tutorial carefully. With the old version, you can only use the second option from the two above. You may want to switch to 2.0 or 2.1 as soon as you can.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.