我有方法傳遞對象的方法函數指針接受[靜態方法指針/全局函數]指針
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;'成員,可以用於這個。 –