Note that there are some explanatory texts on larger screens.

plurals
  1. PO"invalid conversion from" with pthread_create issue
    text
    copied!<p>Any comment is appreciated for the compile error below. Although my question is similar to other thread: <a href="https://stackoverflow.com/questions/1151582/pthread-function-from-a-class">pthread function from a class</a>, I still haven't been able to solve my problem. I am still not that familliar with pointer, and thread programming in C &amp; C++.</p> <p>Error</p> <pre><code>../src/Main.cpp: In function ‘int main(int, char**)’: ../src/Main.cpp:22: error: invalid conversion from ‘unsigned int* (*)(void*)’ to ‘void* (*)(void*)’ ../src/Main.cpp:22: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’ make: *** [src/Main.o] Error 1 </code></pre> <p>Main.cpp</p> <pre><code>#include &lt;process.h&gt; #include "ThreadInstance.hpp" #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; int main(int argc, char** argv) { pthread_mutex_t mutex; int ht1; pthread_t threadId1; pthread_attr_t attr1; pthread_mutex_init(&amp;mutex, NULL); pthread_attr_init(&amp;attr1); pthread_attr_setdetachstate(&amp;attr1, PTHREAD_CREATE_DETACHED); ht1 = pthread_create(&amp;threadId1, &amp;attr1, &amp;ThreadInstance::ThreadEntryPoint, //(void *)readThread); NULL); unsigned long rc = 0; rc = pthread_join(ht1, NULL); return 0; } </code></pre> <p>ThreadInstance.hpp</p> <pre><code>#ifndef _SCENE_CLASSIFY_THREAD_H #define _SCENE_CLASSIFY_THREAD_H #ifndef STDCALL #define STDCALL __attribute__((stdcall)) #endif using namespace std; class ThreadInstance { public: ThreadInstance(); ThreadInstance(int camNum); void startUp(); static unsigned STDCALL* ThreadEntryPoint(void* pThis) { //static unsigned __stdcall ThreadEntryPoint(void* pThis) { ThreadInstance *ptr = (ThreadInstance*) pThis; ptr-&gt;startUp(); //return 1; // Returns error "invalid conversion from ‘int’ to ‘unsigned int*’" when the function is declared as pointer. // Since returning either 1 or 0, // compile error still occurs. // So this return value should not be the cause. return 0; } ~ThreadInstance(); }; #endif </code></pre> <p>Note: Only necessary part is shown</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload