"this"关键字,什么意思?

"this" keyword, what does this mean?

我用谷歌搜索了关键字 "this",其中大多数都给出了类似的例子。

http://www.geeksforgeeks.org/this-pointer-in-c/ http://www.tutorialspoint.com/cplusplus/cpp_this_pointer.htm

当我运行进入这个,

Token::~Token() {
if(this == nullptr) { return; }
.... }

只是没有意义。 "this" 指向什么?如果它指向 'token',它是如何做到的?

this 只是指向函数所属的 class 的当前对象的指针。它更多的是传递给 c++ class 的每个非静态方法的隐藏参数。它只是指向 class 的特定实例以及该对象具有的所有数据。所以对于你的例子:

Token::~Token() {
if(this == nullptr) { return; }
.... }

This 只是指向 Token classes 的析构函数的对象。

if(this == nullptr) { return; }

更具体地说,上面的 if 语句正在查看对象的实例是否等于空引用。

不鼓励在 C++ 中使用 NULL 检查 this。当在指向 class 的 NULL 指针上调用该方法时,this 可能为 NULL。一个例子:

Token* token = nullptr;
token->~Token();

代码确实应该首先检查 token 是否为 NULL,而不是在析构函数中检查 NULL。

Token* token = nullptr;
if (token)
  token->~Token();

这 link 解释了您的问题:http://www.viva64.com/en/b/0226/

Google 和 Foxit 如何解决 pdfium 中的这个问题:

https://bugs.chromium.org/p/pdfium/issues/detail?id=4 https://groups.google.com/forum/#!topic/pdfium/8mTxtmle4ok