Fw: [問題] typedef enum 的 void* 用法請益

看板Programming作者 (Mr.Darcy)時間12年前 (2013/08/26 19:03), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
※ [本文轉錄自 C_and_CPP 看板 #1I6pMLHP ] 作者: remember11 (Mr.Darcy) 看板: C_and_CPP 標題: [問題] typedef enum 的 void* 用法請益 時間: Mon Aug 26 19:01:39 2013 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) G++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 小弟將一段 .c 的code貼到 .cpp上,用 g++ compiler 產上下述錯誤結果 (錯誤的程式在程式碼內兩行標記處 //error) 不知道為什麼c++ 這樣用 void* 會有錯 煩請各位大大指點,該如何改正? 謝謝 錯誤結果(Wrong Output): player.cpp:25: error: invalid cast from type 'void*' to type 'eGOPLAYER_STATE' player.cpp:27: error: invalid cast from type 'void*' to type 'eGOPLAYER_STATE' 程式碼(Code):(請善用置底文網頁, 記得排版) #include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/msg.h> #include <sys/stat.h> #include <malloc.h> #include <unistd.h> typedef enum { eGOPLAYER_STATE_STOP, eGOPLAYER_STATE_PLAY, eGOPLAYER_STATE_PAUSE }eGOPLAYER_STATE; typedef void(* GOPLAYER_STREAM_CALLBACK)(eGOPLAYER_CALLBACK_TYPE type, void *data); void cb_func(eGOPLAYER_CALLBACK_TYPE type, void *data) { switch (type) { case eGOPLAYER_CBT_STATE_CHANGE: { if((eGOPLAYER_STATE)data == eGOPLAYER_STATE_PAUSE) //error printf("[sample]state : pause\n"); else if ((eGOPLAYER_STATE)data == eGOPLAYER_STATE_PLAY){ //error printf("[sample]state : play\n"); } else printf("[sample]state : stop\n"); } break; default: break; } } int player_open_mms(char *uri) { player_open(cb_func); player_set_source_uri(uri, 0); player_close(); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.184.171 ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: remember11 (59.120.184.171), 時間: 08/26/2013 19:03:03 ※ 編輯: remember11 來自: 60.251.192.93 (08/27 13:49)

08/31 11:23, , 1F
if(*(eGOPLAYER_STATE*)data == eGOPLAYE
08/31 11:23, 1F

08/31 11:26, , 2F
原本的程式有錯 改成這樣才對吧
08/31 11:26, 2F
文章代碼(AID): #1I6pNeBj (Programming)
文章代碼(AID): #1I6pNeBj (Programming)