这里令牌预期“)”是代码:前“*”与函数指针
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