Reference of Reference in C++

后端 未结 3 1717
别那么骄傲
别那么骄傲 2020-12-04 11:22

I see code on StackOverflow every once in a while, asking about some overload ambiguity with something involving a function like:

void foo(int&& para         


        
3条回答
  •  误落风尘
    2020-12-04 12:14

    It's an rvalue reference. Note that the && token used for Boolean AND and rvalue references, and the & token used for bitwise AND and normal references, are different "words" as far as the language can tell.

    An rvalue reference is (usually) bound to an object which may be left in an indeterminate state after the rvalue reference is finished, presumably because the object will then be destroyed.

    Simply put, binding a variable to an rvalue reference is the usually the last thing you do to it.

    Unlike a regular reference but like a const & reference, an rvalue reference can bind to an rvalue (an expression whose address cannot be directly taken). Like a regular reference but unlike a const & reference, an rvalue reference can be used to modify its object.

提交回复
热议问题