【发布时间】:2017-04-11 03:08:15
【问题描述】:
我在尝试理解以下代码时卡住了。
class V8_EXPORT Utf8Value {
public:
explicit Utf8Value(Local<v8::Value> obj);
~Utf8Value();
char* operator*() { return str_; }
const char* operator*() const { return str_; }
int length() const { return length_; }
private:
char* str_;
int length_;
Utf8Value(const Utf8Value&);
void operator=(const Utf8Value&);
};
-
行:“~Utf8Value();” 当我检查 cpp 文件时,它只包含一行:
String::Utf8Value::~Utf8Value() { i::DeleteArray(str_); }
意思是说功能是删除char* str_吗?函数名前有~ 有什么原因吗?我可以将其重命名为其他名称而不是 ~Utf8Value?
线路:
const char* operator*() const { return str_; }它有什么作用?为什么函数名后面有*? 我对const的理解是函数/变量永远不会改变,但是括号后面的第二个const是什么意思呢?线路:
Utf8Value(const Utf8Value&);是不是像第一行explicit Utf8Value(Local<v8::Value> obj);这样的另一个构造函数?线路:
void operator=(const Utf8Value&);我不知道这条线想做什么。
谁能帮我解决这个问题?任何帮助将非常感激! 谢谢!!
【问题讨论】:
-
这些是关于课程的基本问题。从长远来看,阅读教科书并解决其中的问题对你来说比获得这些特定问题的答案更有用。
标签: c++ class header declaration