首頁  >  問答  >  主體

c++ - “clobber the lvalue”什么意思?

《c++ primer》讲到右值引用绑定到左值的时候,用了clobber the lvalue这个词,这是什么意思?书中翻译为截断左值(我还是不懂),网上将clobber翻译为连续打击。

Binding an rvalue reference to an lvalue gives code that operates on the rvalue reference permission to clobber the lvalue. There are times, such as in our StrVec reallocate function in § 13.6.1 (p. 533), when we know it is safe to clobber an lvalue. By letting us do the cast, the language allows this usage. By forcing us to use a cast, the language tries to prevent us from doing so accidentally.

PHP中文网PHP中文网2714 天前812

全部回覆(2)我來回復

  • PHP中文网

    PHP中文网2017-04-17 13:15:16

    就是字面意思…
    我的理解是這個左值不再用了,expire了,就透過右值截斷,接管它。它這個名字對應的記憶體中的值或其他資源就不歸它管理了。
    感覺不太好說啊,表達能力捉雞…

    回覆
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:15:16

    常規情況下是不允許右值綁定到左值的(在函數呼叫中)。
    當一個模板函數的形參是右值引用時,而此時如果我們用一個左值實例化它,為了應對這種情況,c++引入了一個例外規則,所以遇到這種情況的時候,編譯器會把模板類型參數推導為實參的左值參考。

    回覆
    0
  • 取消回覆