原文:cannot bind non-const lvalue reference of type 'std::__cxx11::string&

.問題 類的構造函數定義為: 如果這樣初始化對象: 就會報錯誤: cannot bind non const lvalue reference of type std:: cxx ::string amp 而如果構造函數中的string添加了const,就不會報錯了。 .解答 https: stackoverflow.com questions non const lvalue referenc ...

2020-11-22 21:18 0 383 推薦指數:

查看詳情

error: cannot bind non-const lvalue reference of type

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

Sun Feb 23 18:57:00 CST 2020 0 1800
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
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM