※ [本文转录自 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;
}