當試圖理解下面的代碼時,我陷入困境。C++在頭文件中需要類聲明的幫助
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
的理解是,fucntion /變量永遠不會改變,但括號後的第二個const
是什麼意思?行:
Utf8Value(const Utf8Value&);
它是另一種構造函數,像第一行explicit Utf8Value(Local<v8::Value> obj);
?行:
void operator=(const Utf8Value&);
我不知道這一行試圖做什麼。
任何人都可以幫助我嗎?任何幫助將非常感激! 謝謝!
這些是關於類的基本問題。閱讀一本教科書並解決其中的問題,從長遠來看,對你而言,比對這些具體問題的答案更有用。 –