设置 V8 函数时无效使用非静态成员函数

invalid use of non-static member function while setting a v8 function

本文关键字:函数 静态成员 无效 V8 设置      更新时间:2023-10-16

我在类中使用了 v8。 Createcontext 方法也位于包装类中。 当我尝试设置全局并将其映射到也在同一类内的打印函数时,我收到错误非静态成员函数的使用无效

我用来设置方法的行是

global->Set(v8::String::NewFromUtf8(isolate,"print"), v8::FunctionTemplate::New(isolate,this -> print));

有人可以解释为什么会发生此错误以及如何解决它

传递给 FunctionTemplate::New 的函数必须是静态的。因此,尝试将类中的打印函数设置为静态。