2017-03-16 2 views
0

pthread_create関数の引数としてオブジェクトを持つメンバ関数をどのように渡すのですか?pthread_createの引数としてオブジェクトを持つメンバ関数を渡すにはどうすればよいですか?

例:ちょうどこの

void * 
call_member(void *data) 
{ 
    A *a = reinterpret_cast<A *>(data); 
    a->member(); 

    return NULL; 
} 

よう

class A 
    { 
     public: 
     A(){} 

     void funcForThread(Person p) { 
      //code... 
     } 

     void createThread(Person p) { 
      pthread_t thread1; 
      pthread_attr_init (&attr); 
      pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE); 
      pthread_create (&thread1, &attr, /* what to write here*/); // need to pass funcForThread and Person p object there 
     } 

     private: 
     pthread_attr_t attr; 
    }; 
+0

これは、Cではありません。 – Barmar

+1

プロキシ機能を渡す必要があります。 – Barmar

+0

@Barmarプロキシ機能がどのようなものか分かりませんが、例を挙げてください。 – stilltryingbutstillsofar

答えて

0

とCはクラスやメンバ関数を持っていないので、その後、

pthread_create(&thread1, &attr, call_member, this); 
関連する問題