0

我得到的错误:

error C2664: 'v8::FunctionTemplate::New' : cannot convert parameter 1 from 'v8::Handle<T> (__cdecl *)(const v8::Arguments &)' to 'v8::InvocationCallback'

相关定义:

typedef Handle<Value> (*InvocationCallback)(const Arguments& args);




template<class C> class V8ScriptClass
{
public:
    template<class C, typename Rtype, typename Ptype1, Rtype (C::*FuncPtr)(Ptype1)> 
    void RegisterFunc(const char* const scriptname)
    {
        objtemplate->Set(
            v8::String::New(scriptname), 
            v8::FunctionTemplate::New(
            V8ScriptClass<C>::RelayCallback<C, Rtype, Ptype1, FuncPtr>
                ));
    };

template<typename Rtype, typename Ptype1, Rtype (*FuncPtr)(Ptype1 param1)>
static v8::Handle<v8::Value> RelayCallback(const v8::Arguments& args)
{
    std::cerr<<__FUNCTION__<<std::endl;
    v8::HandleScope handle_scope;
    return handle_scope.Close(toJSType( ((FuncPtr)(toCType(args[0]))) ));
};

在我看来 typedef 和实际的函数签名是相同的。

编辑:忘记了一个声明:

class EXPORT FunctionTemplate : public Template {
 public:
  /** Creates a function template.*/
  static Local<FunctionTemplate> New(
      InvocationCallback callback = 0,
      Handle<Value> data = Handle<Value>(),
      Handle<Signature> signature = Handle<Signature>());
4

1 回答 1

1

我发现了错误。RelayCallback 模板将静态函数指针作为参数,我尝试使用成员函数指针对其进行实例化。我只需要将其更改为成员函数指针模板参数。

于 2009-04-01T20:27:45.873 回答