pthread function from a class

前端 未结 9 1084
天命终不由人
天命终不由人 2020-11-22 01:00

Let\'s say I have a class such as

class c { 
    // ...
    void *print(void *){ cout << \"Hello\"; }
}

And then I have a vector of c

9条回答
  •  面向向阳花
    2020-11-22 01:41

    C++ : How to pass class member function to pthread_create()?

    http://thispointer.com/c-how-to-pass-class-member-function-to-pthread_create/

    typedef void * (*THREADFUNCPTR)(void *);
    
    class C { 
       // ...
       void *print(void *) { cout << "Hello"; }
    }
    
    pthread_create(&threadId, NULL, (THREADFUNCPTR) &C::print, NULL);
    

提交回复
热议问题