精華區beta EE_DSnP 關於我們 聯絡資訊
※ 引述《ijb ()》之銘言: : 最近寫作業, 還到某個c跟c++的問題 : 希望有高手幫忙我解答 我不是高手 只是閒閒沒事上網幫忙查了一下^^"" : source code: : http://narcissus.ee.ntu.edu.tw/~yufu/emos_yufu.c : http://narcissus.ee.ntu.edu.tw/~yufu/emos_yufu.cpp : 其中,emos_yufu.c用 : gcc emos_yufu.c -lncurses -lpthread -o hw --> ok,沒任何錯誤 : emos_yufu.cpp用 : g++ emos_yufu.cpp -lncurses -lpthread -o hw --> fail,錯誤訊息如下: : emos_yufu.cpp: In function 'int main()': : emos_yufu.cpp:32: error: invalid conversion from 'void* (*)()' to 'void* (*)(void*)' : emos_yufu.cpp:32: error: initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)' 我查到 pthread_create(&ThreadA,NULL,task1,NULL);的用法 其中ThreadA是一個pthread_t的變數 和你用的一樣 而傳入的第二和第四個參數也和你一樣都是傳入NULL 但task1的function protype是長這樣 void *task1(void *) 我視過如果將你的void *A_Thread_Queue(); 改成 ==> void *A_Thread_Queue(void* i); 就可以work了 所以我想你的error應該是你傳入的東西和它定義的不同吧 我參考的網頁如下 http://www.phptr.com/articles/article.asp?p=169479&seqNum=7&rl=1 : emos_yufu.cpp:37: error: invalid conversion from 'void*' to 'void* (*)(void*)' : emos_yufu.cpp:37: error: initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)' 這個和前一段的問題是一樣的 : emos_yufu.cpp:48: error: void value not ignored as it ought to be 我查了在struct sigaction中的 sighanlder_t 有以下這樣的敘述 sa_hanlder 保存函數的地址,該函數帶一個整型參數,沒有返回值。 它還可以是兩個特別值之一:SIG_DFL 和 SIG_IGN。 然後void func_name(int)就是一個不回傳值的function 當然就不能把它的結果assign給另一個變數吧?? 這是我查到的網頁 http://www.vckbase.com/document/viewdoc/?id=1363 希望沒有幫錯忙^^|| -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.4.242