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

作者: remember11 (Mr.Darcy)   2013-08-26 19:03:03
※ [本文轉錄自 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;
}

Links booklink

Contact Us: admin [ a t ] ucptt.com