原文:C++之error: cannot bind non-const lvalue reference of type ‘myString&’ to an rvalue of type ‘myString’

先看代碼 不想看代碼可以直接看代碼后的問題描述 header.h ifndef HEADER H define HEADER H define defaultSize include lt iostream gt include lt string.h gt using namespace std class myString private: char ch int curLength int ...

2019-09-10 17:01 0 4075 推薦指數:

查看詳情

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