为什么它在这里使用void**?

myv*_*ang 9 c++ v8 reinterpret-cast

代码从v8-0.2.5中提取

/**
 * Checks whether two handles are the same.
 * Returns true if both are empty, or if the objects
 * to which they refer are identical.
 * The handles' references are not checked.
 */
template <class S> bool operator==(Handle<S> that) {
  void** a = reinterpret_cast<void**>(**this);
  void** b = reinterpret_cast<void**>(*that);
  if (a == 0) return b == 0;
  if (b == 0) return false;
  return *a == *b;
}  
Run Code Online (Sandbox Code Playgroud)

Handle超载运算符*,这样**this和*that返回类型T*.

所以它看起来

  void* a = reinterpret_cast<void*>(**this);
  void* b = reinterpret_cast<void*>(*that);
  return a == b;
Run Code Online (Sandbox Code Playgroud)

也会运作良好?

sep*_*p2k 2

如果a和b具有 type void*,那么您无法取消引用它们(不先将它们强制转换为其他内容),所以*a == *b不起作用。

  • 不,你不能,因为在文档注释中它说“对象是相同的”,这意味着它们不必是相同的对象才能返回 true,只要两个不同的对象相同,它们仍然可以比较相等。 (2认同)