I am trying to understand the multithreading in c++. I am trying to call a function in another class using two threads as shown below:
vmgr.h
class VMGR{
public:
int helloFunction(int x);
};
vmgr.cpp
#include"vmgr.h"
#include<iostream>
int VMGR::helloFunction(int x){
std::cout<< "Hello World="<< x << std::endl;
return 0;
}
main.cpp
#include <stdlib.h>
#include <iostream>
#include<iostream>
#include<thread>
#include<chrono>
#include<algorithm>
#include "vmgr.h"
using namespace std::chrono;
int main(int argc, char* argv[]) {
VMGR *vm= new VMGR();
std::thread t1(vm->helloFunction,20);
std::thread t2(vm->helloFunction,30);
t1.join();
t2.join();
return 0;
}
The error I am getting is Invalid use of non-static member function int VMGR:: helloFunction(int)
Not sure how to resolve this error. Thank you in advance.