So I'm trying to thread a member function but while using two different objects of a class (each object has a variable initialized to a different value). I know how to use multithreading if I want to pass a member function inside a class such as:
class ClassA{
public:
void func{}
}
int main{
thread t1(&ClassA func);
thread t2(&ClassA func);
}
Is there a way to use multithreading while referencing to a specific object under a class? I couldn't find anything online specific to this question.
For example we have:
class ClassA{
public:
ClassA(sf::texture tex) : sprite(tex){};
void func(){
//does sth with sprite for this object
}
private:
sf::sprite sprite;
};
int main{
ClassA class1(tex1);
ClassA class2(tex2);
//thread t1(&ClassA func, What should go here?)
//thread t2(&ClassA func, What should go here?)
}
I want to call func of respective class1 and class2 so that they both can use their own initialized tex.