0

I have a code that looks like this

class foo
{
    public:
    foo();
    ~foo();
    int process(); 
};

int main()
{
    foo myfoo1;
    foo myfoo2;

    std::thread firstthread(myfoo1.process());
    std::thread secondthread(myfoo2.process());
    return 0;
}

This is the error that I am getting

'std::invoke': no matching overloaded function found    Disparity   

I know that compiler is complaining because process() is not static but this involves making major changes to the class and I would like not to go that route. Any other hint on how to start the tread?

I cannot do

std::thread firstthread(&foo::process,foo() );

because myfoo1 is different that myfoo2...

Samer
  • 1,923
  • 3
  • 34
  • 54
  • @uneven_mark this is not duplicate, please see my edit... – Samer Oct 01 '19 at 17:52
  • I don't see why it doesn't apply: `std::thread firstthread(&foo::process, myfoo1);` and `std::thread firstthread(&foo::process, myfoo2);` (maybe with `std::ref` wrapper, see duplicate) – walnut Oct 01 '19 at 17:53
  • @uneven_mark, you are right, it works. Thank you. – Samer Oct 01 '19 at 17:55
  • Re, "I know that compiler is complaining because process() is not static..." Um, No. It's complaining because you told it to construct a new `std::thread` instance, using a value of type `foo` as the sole argument to the constructor. This line of code, `std::thread firstthread(myfoo1.process());` first _calls_ `myfoo1.process()`, and then it calls the `thread` constructor, passing the value that was returned by the `process()` call. – Solomon Slow Oct 01 '19 at 20:15
  • Re, "I cannot do...because myfoo1 is different that myfoo2." It looks as if you are just beginning to learn C++. Maybe you should hold off on learning to write multi-threaded programs until later. – Solomon Slow Oct 01 '19 at 20:19

0 Answers0