Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[SFML 2.0] Problem z uzyciem sf::Thread

Ostatnio zmodyfikowano 2014-09-14 13:23
Autor Wiadomość
czosnek17
Temat założony przez niniejszego użytkownika
[SFML 2.0] Problem z uzyciem sf::Thread
» 2014-09-13 23:27:21
Próbuję utworzyć wątek za pomocą sf::Thread, ale nic nie wychodzi. Przykład:
C/C++
void f( int a )
{
    cout << "thread2 " << a << endl;
}

int main()
{
    int asd;
    //to sie kompiluje
    sf::Thread thread( void( * f )( int ) );
    sf::Thread thread( void( * f )( int ), int );
   
    //a to nie
    sf::Thread thread( void( * f )( int ), & asd );
    //error: expected primary-expression before 'int', error: void value not ignored as it ought to be
   
    sf::Thread thread( void( * f )( int ), int );
    thread.launch();
    //error: request for member 'launch' in 'thread', which is of non-class type 'sf::Thread(void (*)(int), int)'
}
Przekazywanie nazwy typu oczywiście nie ma sensu, ale się skompilowało. Funkcji launch() nie udaje się mi wywołać bez błędów.
Dlaczego to nie działa - gdzie jest błąd?
P-116955
colorgreen19
» 2014-09-13 23:41:36
a tak nie możesz zrobić
sf::Thread thread( & f, & asd );
 ?
P-116956
MrPoxipol
» 2014-09-13 23:58:06
albo std::bind()?
P-116957
czosnek17
Temat założony przez niniejszego użytkownika
» 2014-09-14 13:23:37
std::bind() pomogło :)
C/C++
#include <functional>

void f( int a )
{
    cout << "thread2 " << a << endl;
}

int asd = 123;

auto fa = bind( f, asd );
sf::Thread thr( fa );
thr.launch();
P-116972
« 1 »
  Strona 1 z 1