我有方法传递对象的方法函数指针接受[静态方法指针/全局函数]指针
typedef void
(* JSErrorReporter)(JSContext *cx, const char *message, JSErrorReport *report);
JS_SetErrorReporter(JSContext *cx, JSErrorReporter er);
我想传递对象的方法,而不是静态的方法
JS_SetErrorReporter(cx,this->Reporter);//Failed !
那里记者是对象的方法(不是静态的)
JS_SetErrorReporter(cx,Reporter); //Passed
其中报告者是静态方法,dec LARE作为
static void SomeClass::reportError(JSContext *cx, const char *message, JSErrorReport *report)
使用'&SomeClass :: reportError'然后,'this-> Reporter'就是错误的语法(即使是成员函数指针)。无论如何,静态方法不知道“this”。 –
你可以做的是提供一个静态方法,它从某种程度上从上下文获取'this'指针。我不知道'JSContext'是否提供了一些'void * userData;'成员,可以用于这个。 –