c++ - Shift operator usage in terms of classes -


i have line of c++ code , don't know shift operator does:

vrecv >> locator >> hashstop 

identifiers of following types:

  • vrecv: cdatastream cnetmessage::vrecv, instance of cdatastream class , public attribute of cnetmessage class
  • locator: cblocklocator locator, instance of cblocklocator struct
  • hashstop: uint256 hashstop, instance of uint256 class

what important me know, in case?

take @ bitcoin documentation. vrecv instance of cdatastream overloads operator>> read , unserialize data.

background

to understand expression, precedence , associativity of operators important. in c++, >> operator left-associative, means can rewrite expression

(vrecv >> locator) >> hashstop;  // or in terms of actual function calls... ( vrecv.operator>>(locator) ).operator>>(hashstop); 

interpretation

looking @ code operator>> see method takes argument of type t , returns reference itself. in particular case, argument instance of cblocklocator (a stl vector of uint256 elements). notice operator>> calls unserialize reads bytes stream.

thus

(vrecv >> locator) 

reads bytes vrecv stream locator object, returns same stream meaning next executed

vrecv >> hashstop 

which advances stream read bytes hashstop object. so, long story short: fill locator , hashstop objects bytes stream.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -