0

我的模型如下

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++ 类对象相关联。

4

1 回答 1

0

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

于 2012-11-27T19:42:57.657 回答