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 に答える