原文:C++ Error : initial value of reference to non-const must be an lvalue

如下這段代碼,編譯報錯: Error : initial value of reference to non const must be an lvalue include lt iostream gt using namespace std void test float amp x x int main float nKByte . test amp nKByte cout lt lt nKB ...

2014-12-04 08:38 0 2964 推薦指數:

查看詳情

C++ non-const lvalue reference cannot bind to a temporary

1. 問題代碼 2. 編譯錯誤 3. 原因分析 non-const lvalue reference cannot bind to a temporary 根據編譯錯誤提示可以知道,不能將形參begin、end綁定到a.begin()和a.end()的返回值 ...

Tue Mar 10 01:43:00 CST 2020 0 1111
error: cannot bind non-const lvalue reference of type

這種問題一般是因為引用了匿名變量。涉及左值和右值的區別。一般函數的參數如果是一個表達式,那將會產生一個第3方的匿名變量傳入這個函數中,此時如果引用,沒用什么實際意義。 c++中臨時變量不能作為非const的引用參數 ...

Sun Feb 23 18:57:00 CST 2020 0 1800
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM