原文: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