I am trying to write a thread class implementation (a wrapper around pthread API); however, my code does not compile when I use a pointer to a class member function as an argument to the thread start routine. The same code compiles cleanly if I use an ordinary function.
#include
class A{
private:
A();
pthread_t tid;
void *f(void *);
};
A::A(){
pthread_create(&tid, NULL, f, this);
}
void *A::f(void *p){
return NULL;
}
$ xlC_r -c t.cpp
line 11.32: 1540-0286 (W) The unqualified member "f" should be qualified with "::" and preceded by an "&" when forming an expression with type pointer-to-member.
line 11.32: 1540-0256 (S) A parameter of type "extern "C" void *(*)(void *)" cannot be initialized with an expression of type "void *(A::*)(void *)".
line 11.32: 1540-1205 (I) The error occurred while converting to parameter 3 of "pthread_create(pthread_t *, const pthread_attr_t *, extern "C" void *(*)(void *), void *)".
[{"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Component":"Compiler","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF022","label":"OS X"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Compiler","Platform":[{"code":"PF002","label":"AIX"}],"Version":"All Versions","Edition":"Not applicable","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Product":{"code":"SSXVZZ","label":"XL C\/C++ for Linux"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":" ","Platform":[{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"Not Applicable","Line of Business":{"code":"LOB57","label":"Power"}}]
This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use the link to actual document below to access the full document. You will be asked to log on if you are not already logged in. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.