error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ - pthreads

后端 未结 4 597
我在风中等你
我在风中等你 2021-02-14 15:30
anisha@linux-y3pi:~> g++ conditionVarTEST.cpp -Wall

conditionVarTEST.cpp: In function ‘int main()’:
conditionVarTEST.cpp:33:53: error: invalid conversion from ‘void*         


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-14 15:58

    (void *) &functionA will cast your function pointer functionA which is of type void (*)(void*) to a simple void*. The later can't be converted to the first again, so the compiler reports an error. This is one of the reasons why you shouldn't use C-style casts.

    Use pthread_create (&A, NULL, functionA, NULL); instead.

    Also, the return type of a thread function should be void*, not void. So change void functionA(void*) to void* functionA(void*).

提交回复
热议问题