使用Pointer类与v8 FunctionTemplate一起使用会产生错误

时间:2012-11-27 19:08:28

标签: c++ node.js v8 function-template

我的模型如下

using namespace v8;
using namespace node;
class A {
    private:
    //something
    public:
    //something
}
class X {
private: 
    A* a;
public:
    X() {
        a = new A();
    }
    Handle<Value> myfunc(const Arguments& args) {
        //I want to access the instance's "a"
        //like instance->a;
    }
};
Handle<Value> Init(Handle<Object> target) {
    NODE_SET_METHOD(target,'myfunc',Z);
}
Handle<Value> Z(const Arguments& args) {
    X* b = new X();
    Local<FunctionTemplate> tpl = FunctionTemplate::New(b->myfunc);
    //some more code
}

给我以下错误

error: no matching function for call to ‘v8::FunctionTemplate::New(<unresolved overloaded function type>)’ 

我想要实现的目标:

var mymodel=require('build/Release/func.node');
//1. Get a new object
a = mymodel.create();
b = mymodel.create();     

//2. This object has some properties that are generated in C++.
// result of (new X() in C++); 
a.message // "Hello" 
//3. This object has some methods that can use the data stored in C++ instances
a.setMessage("hi") //sets message hi in C++ instance
a.getMessage() // "hi" // retrieves from the C++ Object. 
b.getMessage() // "bazinga" //retrieved from the C++ object

简而言之:

尝试将JavaScript对象与C ++类对象相关联。

1 个答案:

答案 0 :(得分:0)

您无法将FunctionTemplate::New指针传递给成员函数。您需要静态函数或非成员函数。

相关问题