AtheS21 AtheS21 - 1 year ago 50
C++ Question

Why would C++ code increment the 'this' pointer before dereferencing it?

I was wandering through the code of Sequitur G2P and found a really strange line of code:

public:
...
const Node *childrenEnd() const { return (this+1)->finalized.firstChild_; }


I know that
this
is a pointer to the current object, and since it is a pointer, the operation is perfectly legal, but what does
this+1
actually refer to?

Answer Source

Presumably this is part of an array, so this+1 would refer to the next object in that array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download