简体   繁体   English

V8 Hello World编译错误:无法从&#39;v8 :: Local转换 <v8::String> &#39;to&#39;v8 :: String&#39;

[英]V8 Hello World compilation error: cannot convert from 'v8::Local<v8::String>' to 'v8::String'

I am new to V8. 我是V8的新手。 I was trying to run the Hello World example form here . 我试图在这里运行Hello World示例表单。

But, I am getting compilation error at this line: 但是,我在这一行得到编译错误:

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

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

Why am I getting this error? 为什么我收到此错误?

The String class changed. String类已更改。 It does not have anymore the New method; 它不再具有New方法; it has NewFrom* methods: 它有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)

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

A string can be created this way: 可以通过以下方式创建字符串:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM