在将其标记为重复之前,我已经看到了其他答案,但它们没有解决我的问题。
我有两个类如下:
A.cpp:
class A
{
public:
A();
int getValue()//just an example of a get method
{
return value;
}
private:
int value;
// a lot of variables
}
Run Code Online (Sandbox Code Playgroud)
B.cpp:
class B
{
public:
B();
void addData(string fileName)
{
A* a = new A();
//reads the file with the fileName and does alot of stuff
//after calculation is over it adds the object to the vector
list.push_back(a);
}
void run()
{
thread t1(&B::simulate, list[0]);
thread t2(&B::simulate, list[1]);
t1.join();
t2.join();
} …Run Code Online (Sandbox Code Playgroud)