C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std
编译异常如下:
解决办法:
我的函数是这样的
string &larger(const string &s1, const string &s2){return s1.size() > s2.size()? s1 : s2;
}
改成这样就行了
const string &larger(const string &s1, const string &s2){return s1.size() > s2.size()? s1 : s2;
}
忘记加const
总结:
下次写函数要注意,如果参数字符串都是const,返回的引用的类型也是const,const请保持一致,在C++里面很重要,还是得把C++里面的 const关键字多总结。
C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std相关推荐
- 传参时 const string 相对 const string 有哪些优势?
C++中值传递和引用传递的方式. C++的值传递(pass-by-value),是从调用的地方把值复制一遍传给函数,这样做有两个问题,第一,需要将实参拷贝到形参处,形成实参的副本,有时间和空间的开销, ...
- 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 ...
- no match for call to ‘(std::__cxx11::string {aka std::__cxx11::basic_string
问题: t->package().ship_id(sqlRow[1]); 其中 ship_id为 结构体package中的string类型. 如下: typedef struct Packag ...
- 【报错】关于[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 ...
- 函数传参数时,const string和 const string 的区别
const string 是值传递 const string& 是引用传递 值传递:是将要传递的值复制一遍传过来,也就是将实参拷贝到形参处,形成实参的副本,在修改副本的时候实参是不会有任何变化 ...
- C++非const引用问题:error: cannot bind non-const lvalue reference of type
出现这个问题是因为把一个临时变量传入了函数的引用形参中,简化代码如下: void back(int &i){return; }int main(){back(1); } 应该改为: void ...
- leetcode报错runtime error: reference binding to null pointer of type ‘std::vector<std::__cxx11::basic_
leetcode报错:runtime error: reference binding to null pointer of type 'std::vector<std::__cxx11::ba ...
- LeetCode报错:Line 923: Char 9: runtime error: reference binding to null pointer of type ‘std::__cxx11:
LeetCode报错 报错原因: Line 923: Char 9: runtime error: reference binding to null pointer of type 'std::__ ...
- 成员函数对象类的const和非const成员函数的重载
首先声明,我是一个菜鸟.一下文章中出现技术误导情况盖不负责 1. 类的const成员函数与非const成员函数的载重 #include <iostream> #include <st ...
最新文章
- 我们软件是如何保障用户数据安全的?
- plt.hist绘制直方图参数density 为True和False分别代表是否归一化 参数orientation决定了是采用纵轴代表频率还是横轴代表频率的展现形式
- 隐形需求 软件测试,从开发角度聊聊如何洞悉隐性需求
- MySQL 高级 - 存储过程 - 语法 - while循环
- 图解Windows网络命令使用实例
- VS2019-写opengl时Bugs合集(持续更新)
- android 布局点击效果,如何让LinearLayout也有类似Button的点击效果?
- C++11之std::async使用介绍
- 清除error.log、access.log并限制Apache日志文件大小的方法
- WeLive开源PHP在线客服系统源码
- /bin/false /sbin/nologin
- IDC服务器共享带宽和独享带宽的区别
- python可视化编程软件下载_mPython-mPython(图形化编程软件)下载 v0.5.0官方版-下载啦...
- 光学设计知识总结(ZEMAX预备知识)
- c# formApp的web browser的兼容性设置
- 解决win10系统电脑桌面没有此电脑 没有我的电脑
- 解决谷歌浏览器form表单自动填充
- 计算机考试完后去哪领证,税务师考试全科通过后去哪领证?
- 常用的html代码 加粗 加亮 字型加大 变色等
- 1+1≠2 |A/B 测试中的赢者诅咒
热门文章
- Magicodes.IE之花式导出
- 你需要了解操作系统发展历程
- 抱歉,请不要把 “业务逻辑层” 理解为 “业务中台”
- .NET Core开发实战(第16课:选项数据热更新:让服务感知配置的变化)--学习笔记...
- 【新书推荐】《ASP.NET Core微服务实战:在云环境中开发、测试和部署跨平台服务》 带你走近微服务开发...
- 【.NETCore 3】Ids4 ║ 统一角色管理(上)
- 用pythonnet为计算机视觉做图像整理
- 博客园升级有感一点建议
- Ocelot(五)- 流量限制、服务质量
- 事关SuperSocket发布,寻找YangFan哥哥