search

Home  >  Q&A  >  body text

c++中this[i]的用法是什么语法?

在webkit中看到一段代码:
class ExecState : public Register { JSValue calleeAsValue() const { return this[JSStack::Callee].jsValue(); } ... }
其中JSStack::Callee是常量,不管是ExecState还是Register都没有对operator[]进行重载,所以想不明白this[JSStack::Callee]这样的用法是什么意思?

巴扎黑巴扎黑2767 days ago442

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 11:34:46

    This has nothing to do with the overloading of operator[], because this is a pointer to itself, and *this is an instance of ExecState.

    Then the question is how to understand it from the C language level. this[JSStack::Callee]Actually *(this + JSStack::Callee). Although I have not understood the code of webkit, I guess that the calling condition of calleeAsValue() is that this instance is in an array (perhaps a stack implemented with an array?), so that code makes sense.

    reply
    0
  • Cancelreply