AtheS21 AtheS21 - 2 years ago 74
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:

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

I know that
is a pointer to the current object, and since it is a pointer, the operation is perfectly legal, but what does
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