-
Hi!
How to create a thread(with args) from the method?
class A
{
public:
A()
{
// understood that does not work
pThread = new sf::Thread(std::bind(&Method, 15, 25), this));
}
~A()
{
delete pThread;
}
void Method(int a, int b);
private:
sf::Thread* pThread;
};
-
Try this:
pThread = new sf::Thread(std::bind(&A::Method, this, 15, 25)));
And since you have std::bind, I guess you also have std::thread; why don't you use it?
-
I don't think you need pointers here. Use RAII (http://www.bromeon.ch/articles/raii.html), it makes your code simpler and correct (because currently it's not, see Rule Of Three):
class A
{
public:
A() : Thread(std::bind(&A::Method, this, 15, 25)) {}
// no need for destructor
void Method(int a, int b);
private:
sf::Thread pThread;
};
-
Thanks to all! ;D