I am from a Java background and is learning C++. I encountered the following C++ code:
String source = String::New("'Hello' + ', World'");
As what I understand so far, this should be a call to static member function ‘New’ of class ‘String’. But, I’ve searched through the whole header file defining ‘String’, there is not any static member named ‘New’ in the String class or its super classes. Is there any special meaning attached to String class or the New member function in C++?
You are correct. That is calling the
staticmethodNewon theStringclass.C++ (or STL) doesn’t have a native
Stringclass, there is astringclass, but it doesn’t have a::Newmethod. You’ll have to make sure you’re reading the right documentation 🙂It’s possible that it’s inherited from a base-class, so make sure you check if
Stringis part of an inheritance hierarchy.Here’s the deal with v8’s String. It’s interesting.
There are two implementations:
Browsing the internal String source code,
Stringis indeed a heap allocated object representing a Javascript string.It turns out that Google Code’s UI is broken (maybe they have a maximum character count?). The v8::internal::HeapObject source code should be in
src/objects.h, but the file is truncated. And the externally visible v8::String source code should be ininclude/v8.h, but it too is truncated.You can download the source and view the files. Here is what it says: