error: non-const lvalue reference to type cannot bind to a value of unrelated type
项目场景:
在项目代码编译中报错信息如下:
error: non-const lvalue reference to type '...' cannot bind to a value of unrelated type '...'
问题描述:
将项目问题进行简单抽象后等价于以下问题:
这样做编译通过
int a;const double& m = a;
但这样做编译报错
int a;double& m = a;
报错信息如标题
原因分析:
因为临时变量不能被绑定在一个non-const reference上
double& m = a;
a
是一个int变量, 会被隐式转换为double类型变量, 所以这个过程就生成了一个临时变量, non-const reference不能绑定临时变量
解决方案:
避免隐式转换, 或加const
error: non-const lvalue reference to type cannot bind to a value of unrelated type相关推荐
- 【C++---const引用】数组进行指针引用传递给函数error: non-const lvalue reference of type ‘int*‘ to an rvalue
目录 原因 类型转换 手动转换 自动转换 关于临时量 关于常量引用(const的引用) const引用的对象不是不能被修改了吗,这里为什么被修改了? 不是说是const引用吗?为什么又变成了引用所绑定 ...
- 【报错】关于[Error] cannot bind non-const lvalue reference of type ‘std::String‘ to an rvalue……的一个解决方案
使用dev c++进行一波教科书代码的练习时出现了一点问题,于是来记录一波. 报错信息如下: [Error] cannot bind non-const lvalue reference of typ ...
- QT之error: cannot bind non-const lvalue reference of type ‘CBaowen’ to an rvalue of type ‘CBaowen
问题描述:QT中自己编写了一个结构体变量CBaowen,报文中含有函数重载部分(如下所示), 之后定义一个队列变量 QQueue<CBaowen> queue; 当给队列变量赋值时que ...
- error: invalid initialization of reference of type ‘std::string’ from expression of type ‘const s
error: invalid initialization of reference of type 'std::string&' from expression of type 'const ...
- cannot bind non-const lvalue reference of type ‘xxx‘ to an rvalue of type ‘xxx‘
文章目录 报错代码 报错 原因 解决方案 报错代码 #include<iostream> using namespace std; class Complex{private:double ...
- cannot bind non-const lvalue reference of type ‘***‘ to an rvalue of type ‘***‘解决方法
在写C++作业的时候,我发现使用 #include <iostream> class complex{public:int real;int imaginary;public:comple ...
- 关于C++的cannot bind non-const lvalue reference of type...问题
关于C++的cannot bind non-const lvalue reference of type-问题 先看下面的代码,一个很简单的切分字符串并输出的函数. #include <iost ...
- error: invalid initialization of reference of type ‘plb::MultiContainerBlock3D’ from expression of
最近在某学校的服务器上装老版本的Palabos,结果编译的时候还有这回事: error: invalid initialization of reference of type 'plb::Multi ...
- C++ 语言左值引用 (lvalue reference)
C++ 语言左值引用 (lvalue reference) C++11 中新增了右值引用 (rvalue reference).当我们使用术语引用 (reference) 时,指的其实是左值引用 (l ...
最新文章
- JEECMS8——系列文档
- 是什么_什么是模电,什么是数电
- 首次使用eclipes运行项目报错“Java.lang.ClassNotFoundException”
- C语言高级编程:char、signed char 和 unsigned char的使用区别
- 深入理解 ajax_xhr 对象
- Linux文件编程(2)
- 外星人台式电脑_戴尔 XPS 和外星人大更新,一边是生产力,一边是游戏
- python分割合并文件
- OpenCV自适应阈值分割函数:adaptiveThreshold()介绍
- ActionMapping
- Java设计模式百例 - 原型模式
- iPhone4 降级6.12教程 无须SHSH 不装插件 不睡死[转载] by 轻鸢
- mp4的box信息——avcC,mdat
- 图嵌入中节点如何映射到向量
- JavaScript防抖(王者荣耀回城)、节流(王者荣耀技能读条)
- uniapp 微信云开发静态网站和云函数跳转小程序
- java.sql.SQLException: Table 'XXX' is marked as crashed and should be repaired异常修复
- 软件工程师应具备什么样的素质
- 出圈c语言,c语言作业 出圈游戏
- 符合SEO标准的div+css页面参考