项目场景:

在项目代码编译中报错信息如下:

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相关推荐

  1. 【C++---const引用】数组进行指针引用传递给函数error: non-const lvalue reference of type ‘int*‘ to an rvalue

    目录 原因 类型转换 手动转换 自动转换 关于临时量 关于常量引用(const的引用) const引用的对象不是不能被修改了吗,这里为什么被修改了? 不是说是const引用吗?为什么又变成了引用所绑定 ...

  2. 【报错】关于[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 ...

  3. QT之error: cannot bind non-const lvalue reference of type ‘CBaowen’ to an rvalue of type ‘CBaowen

    问题描述:QT中自己编写了一个结构体变量CBaowen,报文中含有函数重载部分(如下所示), 之后定义一个队列变量 QQueue<CBaowen>  queue; 当给队列变量赋值时que ...

  4. 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 ...

  5. cannot bind non-const lvalue reference of type ‘xxx‘ to an rvalue of type ‘xxx‘

    文章目录 报错代码 报错 原因 解决方案 报错代码 #include<iostream> using namespace std; class Complex{private:double ...

  6. 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 ...

  7. 关于C++的cannot bind non-const lvalue reference of type...问题

    关于C++的cannot bind non-const lvalue reference of type-问题 先看下面的代码,一个很简单的切分字符串并输出的函数. #include <iost ...

  8. error: invalid initialization of reference of type ‘plb::MultiContainerBlock3D’ from expression of

    最近在某学校的服务器上装老版本的Palabos,结果编译的时候还有这回事: error: invalid initialization of reference of type 'plb::Multi ...

  9. C++ 语言左值引用 (lvalue reference)

    C++ 语言左值引用 (lvalue reference) C++11 中新增了右值引用 (rvalue reference).当我们使用术语引用 (reference) 时,指的其实是左值引用 (l ...

最新文章

  1. JEECMS8——系列文档
  2. 是什么_什么是模电,什么是数电
  3. 首次使用eclipes运行项目报错“Java.lang.ClassNotFoundException”
  4. C语言高级编程:char、signed char 和 unsigned char的使用区别
  5. 深入理解 ajax_xhr 对象
  6. Linux文件编程(2)
  7. 外星人台式电脑_戴尔 XPS 和外星人大更新,一边是生产力,一边是游戏
  8. python分割合并文件
  9. OpenCV自适应阈值分割函数:adaptiveThreshold()介绍
  10. ActionMapping
  11. Java设计模式百例 - 原型模式
  12. iPhone4 降级6.12教程 无须SHSH 不装插件 不睡死[转载] by 轻鸢
  13. mp4的box信息——avcC,mdat
  14. 图嵌入中节点如何映射到向量
  15. JavaScript防抖(王者荣耀回城)、节流(王者荣耀技能读条)
  16. uniapp 微信云开发静态网站和云函数跳转小程序
  17. java.sql.SQLException: Table 'XXX' is marked as crashed and should be repaired异常修复
  18. 软件工程师应具备什么样的素质
  19. 出圈c语言,c语言作业 出圈游戏
  20. 符合SEO标准的div+css页面参考

热门文章

  1. 计算机演示文稿方案文稿,全国计算机等级考试二级officeppt演示文稿题目
  2. 重温C语言十四-----结构体与共用体
  3. 开发环境、测试环境、生产环境、UAT环境
  4. Word中如何将多级列表与标题样式关联起来
  5. 分治算法——汉诺塔(HanoiTower)
  6. 【前端开发】CSS BEM命名规范
  7. IQ调制Matlab代码
  8. Linux如何卸载slurm,RedHat安装SLURM
  9. 基于springboot+vue+elementui的游戏攻略分享平台
  10. 2023企业数智化财务创新峰会西安站圆满举办