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*)'
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
1.想要請教為什麼一樣的code,在c compiler可以過,c++ compiler不能過??
2.void*(*)(void*)的參數要怎麼寫啊??
3.還有像48的error
act_new.sa_handler=TimePrint();
不能這樣子寫,我有去查sa_handler,它需要傳入的是void func_name(int)
我也在這行之上加上過int i=0;
然後改寫act_new.sa_handler=TimePrint(0);
結果錯誤還是一樣....囧rz啊....
我也有試過傳入值前面拿掉&,像A_Thread_Queue的作法(原本是&A_Thread_Queue),
一樣可以通過compiler,而且也可以執行....
所以證明這樣的寫法在c,c++應該都是pass by reference(希望我的想法沒錯),
還是哪裡有錯呢??????????????????
又是拉里拉雜....連自己都快要搞不懂了.囧.............
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.42.185
最近寫作業, 還到某個c跟c++的問題
希望有高手幫忙我解答
source code: