当前位置:网站首页>What is an R-value reference and what is the difference between it and an l-value?

What is an R-value reference and what is the difference between it and an l-value?

2022-07-06 08:51:00 it_ xiangqiang



Right value reference and left value reference


Right quoting

The right quotation is C++11 New features introduced in , It implements transfer semantics and precise delivery . Its main

The purpose has two aspects :


  1. Eliminate unnecessary copy of objects when two objects interact , Save computing and storage resources , Increase of efficiency .
  2. Can be more concise and clear definition of generic functions .

The concepts of left and right values :

The left value : Can take address for expression 、 Or named objects / Variable . A persistent object that still exists after the end of an expression .

Right value : Cannot address an expression , Or anonymous objects . A temporary object that no longer exists at the end of an expression .

The difference between right and left references :


  1. Left values can address , And right value can't .
  2. Left values can be assigned , Right values cannot be assigned , It can be used to assign values to left values .
  3. Left variable , The right value is immutable ( For foundation types only , The right value reference of user-defined type can be through member function
    change ).


原网站

版权声明
本文为[it_ xiangqiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131806320645.html