[問題] typedef enum 的 void* 用法請益
開發平台(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
※ remember11:轉錄至看板 Programming 08/26 19:03
推
08/26 19:19, , 1F
08/26 19:19, 1F
→
08/26 19:20, , 2F
08/26 19:20, 2F
謝謝
不過這樣改似乎就失去callback的意義喔?
推
08/26 19:31, , 3F
08/26 19:31, 3F
→
08/26 22:19, , 4F
08/26 22:19, 4F
推
08/27 00:56, , 5F
08/27 00:56, 5F
→
08/27 00:57, , 6F
08/27 00:57, 6F
→
08/27 01:05, , 7F
08/27 01:05, 7F
謝謝
不過兩個方法都試過
compiler一樣有error
所以C++沒辦法這樣寫?
※ 編輯: remember11 來自: 60.251.192.93 (08/27 13:47)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):