I decided to try creating a simple C wrapper for the V8 API using the model described in Developing C wrapper API for Object-Oriented C++ code. Unfortunately, I'm not too familiar with C++, so I'm running into an issue with inherited constructors.
v8capi.h
typedef struct V8Context V8Context;
#ifdef __cplusplus
extern "C" {
#endif
V8Context *V8_NewContext();
#ifdef __cplusplus
}
#endif
v8capi.cpp
#include <v8.h>
struct V8Context : public v8::Handle<v8::Context> { };
V8Context *V8_NewContext() {
v8::HandleScope hscope;
return new V8Context(v8::Context::New());
}
From what I understand, new V8Context(...) should call v8::Handle<T>'s constructor which takes a Handle<T>. v8::Context::New() returns a v8::Persistent<T>, which inherits v8::Handle<T>, so that should work. But in reality, it's trying to call a constructor that takes a const V8Context &:
error C2664: 'V8Context::V8Context' : cannot convert parameter 1 from
'v8::Persistent<T>' to 'const V8Context &'
with
[
T=v8::Context
]
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
What am I doing wrong?