這裏令牌預期「)」是代碼:前「*」與函數指針
typedef struct {
void (*drawFunc) (void*);
} glesContext;
void glesRegisterDrawFunction(glesContext *glesContext, void(drawFunc*)(glesContext*));
對於最後一行,我得到的錯誤信息:「之前‘*’令牌預期‘)’」
爲什麼?
這裏令牌預期「)」是代碼:前「*」與函數指針
typedef struct {
void (*drawFunc) (void*);
} glesContext;
void glesRegisterDrawFunction(glesContext *glesContext, void(drawFunc*)(glesContext*));
對於最後一行,我得到的錯誤信息:「之前‘*’令牌預期‘)’」
爲什麼?
你可能想嘗試把它放在圓括號中:glesContext * glesContext。
我真的不知道你的代碼試圖做的,但如果你只是想編譯它,嘗試
void glesRegisterDrawFunction(glesContext *glesContext, void (*drawFunc)(glesContext*));
您有做一個函數指針的正確方法你struct
(所以很榮幸,很多人都錯了)。
但是你已經在你的函數定義中替換了drawFunc
和*
,這是編譯器抱怨的原因之一。另一個原因是你有相同的標識符被用作類型和變量。您應該選擇不同的兩種不同事物的標識符。
使用這個代替:
void glesRegisterDrawFunction(glesContext *cntxt, void(*drawFunc)(glesContext*));
^^^^^^^^^
note here
一種解決方案是增加一個函數指針的typedef如下:
typedef struct {
void (*drawFunc) (void*);
} glesContext;
// define a pointer to function typedef
typedef void (*DRAW_FUNC)(glesContext*);
// now use this typedef to create the function declaration
void glesRegisterDrawFunction(glesContext *glesContext, DRAW_FUNC func);
Typedeffing函數指針可以讓他們更容易處理。 – dreamlax 2012-02-20 03:14:12