[Solved] Shift operator usage in terms of classes


Take a look at the BitCoin documentation. vRecv is an instance of CDataStream which overloads the operator>> to read and unserialize data.

Background

To understand the expression, precedence and associativity of operators are important. In C++, the >> operator is left-associative, which means you can rewrite your expression

(vRecv >> locator) >> hashStop;

// Or in terms of actual function calls...
( vRecv.operator>>(locator) ).operator>>(hashStop);

Interpretation

Looking at the code for the operator>> you see that the method takes an argument of type T and returns a reference to itself. In your particular case, the argument is an instance of CBlockLocator (a STL vector of uint256 elements). Notice that the operator>> calls Unserialize which effectively reads bytes from a stream.

Thus

(vRecv >> locator)

reads bytes from the vRecv stream into your locator object, returns the same stream meaning that next this is executed

vRecv >> hashStop

which advances the stream to read bytes into the hashStop object. So, long story short: fill the locator and hashStop objects with bytes from the stream.

6

solved Shift operator usage in terms of classes