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

Author Topic: Is it possible to make a sf::Thread to a function with more than one parameter?  (Read 4437 times)

0 Members and 1 Guest are viewing this topic.

bobtran12

  • Guest
Is it possible to make a sf::Thread to a function with more than one parameter?

For example, I want to make a thread that starts the following function:
void func(int A, double B, double C, string D) {}

Not sure if I am overlooking something, but I can only make it if the function has at most one parameter. Such as:
void func(int A) {}

int main()
{
        sf::Thread thread(func, A);
}
« Last Edit: July 21, 2015, 07:30:36 am by bobtran12 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
No. Use std::thread if your compiler supports it.
Laurent Gomila - SFML developer

bobtran12

  • Guest
What if I did this?

void func(int A, double B, double C, string D) {}

int main()
{
    sf::Thread thread(std::bind(func, A, B, C, D));
}

Or is there something wrong with that?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
It works, but... if your compiler supports std::bind then std::thread is also probably available. There's no reason not to use it.
Laurent Gomila - SFML developer

bobtran12

  • Guest
It works, but... if your compiler supports std::bind then std::thread is also probably available. There's no reason not to use it.
I guess you're right. I'll use std::thread instead. Thanks!

 

anything