SFML community forums

Help => System => Topic started by: bobtran12 on July 21, 2015, 07:24:12 am

Title: Is it possible to make a sf::Thread to a function with more than one parameter?
Post by: bobtran12 on July 21, 2015, 07:24:12 am
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);
}
Title: Re: Is it possible to make a sf::Thread to a function with more than one parameter?
Post by: Laurent on July 21, 2015, 07:35:30 am
No. Use std::thread if your compiler supports it.
Title: Re: Is it possible to make a sf::Thread to a function with more than one parameter?
Post by: bobtran12 on July 21, 2015, 09:22:01 am
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?
Title: Re: Is it possible to make a sf::Thread to a function with more than one parameter?
Post by: Laurent on July 21, 2015, 09:41:02 am
It works, but... if your compiler supports std::bind then std::thread is also probably available. There's no reason not to use it.
Title: Re: Is it possible to make a sf::Thread to a function with more than one parameter?
Post by: bobtran12 on July 21, 2015, 09:45:11 am
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!