8

Before marking this as duplicate, I have already seen the other answers and they did not solve my issue.

I have two classes as follows:

A.cpp:

class A { public: A(); int getValue()//just an example of a get method { return value; } private: int value; // a lot of variables } 

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(); } private: vector<A*> list; void simulate(A* ptr) { int value = 0; cout << "At first value is " << value << endl; weight = ptr->getValue(); cout << "Then it becomes " << value << endl; } } 

And then I have a simple main.cpp:

 int main() { B* b = new B(); b->addData("File1.txt"); b->addData("File2.txt"); b->run(); return 0; } 

I am trying to create two threads by calling the method run(). However, when I try to compile I get the following error:

 error C2672: 'std::invoke': no matching overloaded function found 

I checked the other posts but nothing seemed to work for me. Any help would be appreciated.

P.S: I am using the following includes:

 #include <thread> #include <iostream> 

and also:

using namespace std; 

I am using other includes but they are irrelevant

1
  • 1
    That's a lot of white space.... Commented May 1, 2017 at 6:12

1 Answer 1

4

B::simulate is a non-static member function so it requires 2 parameters - this and ptr, while you supplying only one. You should redeclare it as static since it does not access this class members anyway.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.