gpt4 book ai didi

c++ - V8 Hello World编译错误: cannot convert from 'v8::Local' to 'v8::String'

转载 作者:行者123 更新时间:2023-11-30 02:50:00 25 4
gpt4 key购买 nike

我是 V8 的新手。我试图运行 Hello World 示例表单 here .

但是,我在这一行遇到了编译错误:

v8::String source = v8::String::New("'Hello' + ', World'");

error C2440: 'initializing' : cannot convert from 'v8::Local<v8::String>' to 'v8::String'

为什么会出现此错误?

最佳答案

String 类发生了变化。它不再有 New 方法;它有 NewFrom* 方法:

static Local< String >  NewFromUtf8 (Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
static Local< String > NewFromOneByte (Isolate *isolate, const uint8_t *data, NewStringType type=kNormalString, int length=-1)
static Local< String > NewFromTwoByte (Isolate *isolate, const uint16_t *data, NewStringType type=kNormalString, int length=-1)

您可以浏览 doxygen 文档:http://bespin.cz/~ondras/html/classv8_1_1String.html#aa4b8c052f5108ca6350c45922602b9d4

可以这样创建一个字符串:

v8::Isolate* i = v8::Isolate::New();//create an isolate instance
//( if you already have one just get it: GetIsolate()
//=>http://bespin.cz/~ondras/html/classv8_1_1Context.html
v8::Local<v8::String> constant_name = v8::String::NewFromUtf8(i,"asd");
i->Dispose();

关于c++ - V8 Hello World编译错误: cannot convert from 'v8::Local<v8::String>' to 'v8::String' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20835320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com