multithreading - Error while trying to create simple thread in c++ -
im trying create simple thread , have execute.
my function definition is:
void myclass::myfunction() { //do work }
i'm creating thread , executing it:
std::thread t1(myfunction);
upon compiling code, following error:
error c3867: function call missing argument list; use '&myclass::myfunction' create pointer member.
since function not take parameters, i'm assuming i'm declaring wrongly i'm creating thread? appreciated, thanks!!
- if method non-static member : need instance of object call member function on.
- if method static member, compiler suggest : pass address of function.
example:
class { public: void foo() { cout << "foo"; } static void bar() { cout << "bar"; } }; int main() { std::thread t1(&a::foo, a()); // non static member t1.join(); std::thread t2(&a::bar); // static member (the synthax suggested compiler) t2.join(); return 0; }
Comments
Post a Comment