error: passing ‘const xxx’ as ‘this’ argument discards qualifiers [-fpermissive]的解决方案
先上错误:
../include/rectangle.h: In instantiation of 'R_START_TREE::Rectangle<dimensions>& R_START_TREE::Rectangle<dimensions>::operator=(const R_START_TREE::Rectangle<dimensions>&) [with long long unsigned int dimensions = 3]':
rectangle_test.cpp:50:41: required from here
../include/rectangle.h:79:33: error: passing 'const R_START_TREE::Rectangle<3>' as 'this' argument discards qualifiers [-fpermissive]
this->lowerLeft = rectangle.getLowerLeft();
错误解释:
直译:错误:将“const xxx”作为“this”参数传递会丢弃限定词。
- discards qualifiers:丢弃限定符,当尝试修改const类型时,会报discards qualifiers
- -fpermissive:将有关不合格代码的某些诊断从错误降级为警告。因此,使用-fpermissive将允许编译一些不合格的代码。
放到我们的代码里,就是下面的两个this的赋值。下面的代码是要重载=运算符,就是将rectangle的左下角和右上角(Point类对象)赋给this的左下角和右上角这两个私有变量。
Rectangle & operator=(const Rectangle &rectangle){if(this != &rectangle){this->lowerLeft = rectangle.getLowerLeft();this->setUpperRight(rectangle.getUpperRight());}return *this;}Point<dimensions> getLowerLeft()
{return lowerLeft;
}Point<dimensions> getUpperRight()
{return upperRight;
}
根据上述原因,我们可以确定,是因为Rectangle类的getUpperRight()和getLowerLeft()函数返回值都不是const限定的,所以,我们只需要修改这俩函数的声明即可。后面在对类中的getXXX()返回类的对象的时候,还是要尽量用const限定。
Point<dimensions> getLowerLeft() const
{return lowerLeft;
}Point<dimensions> getUpperRight() const
{return upperRight;
}
error: passing ‘const xxx’ as ‘this’ argument discards qualifiers [-fpermissive]的解决方案相关推荐
- error: passing ‘const xxx’ as ‘this’ argument discards qualifiers c++primer 5th文本查询程序一个错误请各位指教(已解决)
文件main.cc 文件main.cc #include <string> #include <iostream> #include <memory> #inclu ...
- C++ STL编译报错:error: error passing 'const' as 'this' argument
用C++ STL(标准模板库)编写仿函数的时候,编译报错: error: passing 'const FindNameOrAddress' as 'this' argument of 'bool F ...
- C++编程常见问题—error: passing 'const std::map]' discards qualifiers或pass-by-reference-to-const-map导致的“d
产生问题的场景: int func(const map<int, string> &aMap) { string value = amap[0]; } 或者 int Test:: ...
- 【c++常见错误01】error C2662: ‘const xxx‘: cannot convert ‘this‘ pointer from ‘xxx‘ to ‘xxx‘
原因 造成这个错误的一般原因是常量对象尝试调用该对象里的非常量函数,例如class Bala里有一个普通的成员函数func(),在某处声明了Bala类常量对象bala,const Bala bala, ...
- C++ ERROR:error: passing 'XXX' as 'this' argument of 'XXX' discards qualifiers
遇到了如题目的这种错误: error: passing 'XXX' as 'this' argument of 'XXX' discards qualifiers 如何产生的? 我将一个const变量 ...
- 1. 无法解析的外部符号 “__declspec(dllimport) const XXX::vftable“ ` 2. `无法定义 dllimport 实体`
由于自己C++基础薄弱,导致这一系列的Bug改了好久好久....记录一部分,我还记得的 编译通过镇一下哈哈 Bug1 error LNK2001: 无法解析的外部符号 "__declspec ...
- Eclipse error: “The import XXX cannot be resolved”
解决 Eclipse error: "The import XXX cannot be resolved" eclipse中修改: 1. 项目-->Properties--& ...
- IDEA中进行SpringBoot开发时提示:Error resolving template xxx, template might not exist or might not be acce
场景 IDEA中进行SpringBoot开发时提示: Error resolving template "xxx", template might not exist or mig ...
- Runtime error 216 at xxx 故障解决一例
2019独角兽企业重金招聘Python工程师标准>>> 故障现象:部分Delphi项目在win7开发机上不能运行了,提示Runtime error 216 at xxx错误信息,但是 ...
- 异常:Error resolving template “xxx“, template might not exist or might not be accessible...解决办法
异常:Error resolving template "xxx", template might not exist or might not be accessible...解 ...
最新文章
- c语言结点初始化,C语言双向链表简单实现及图示(初始化/插入节点/删除节点)...
- 剑指offer-链表中倒数第K个结点
- 对AI毫无了解?本文带你轻松了解AI
- python 装饰器实现_Python装饰器系列01 - 如何正确地实现装饰器
- 【渝粤教育】国家开放大学2019年春季 1260软件工程 参考试题
- Stanford机器学习---第十一讲.异常检测
- java手游+刺客_元气骑士手游教你如何成为一名顶尖流刺客
- 金蝶BOS开发之--非空验证、时间、电话号码验证
- 【翻译】BCGControlBar Professional Edition for MFC v 29.0重大更新
- paip.索引优化---sql distict—order by 法
- lwip协议栈源码分析之pbuf
- python利用re正则匹配替换句子中的特殊字符(如中文逗号','变英文逗号',',英文句号'.'变中文句号'。'等)
- Oracle视图(View)----------------数据库中虚拟的表
- 【HDU4416】Good Article Good sentence【后缀数组】
- 神经平面分布图怎么看,面部神经网络 分布图
- 采样开关的作用计算机控制,计算机控制系统复习要点
- Selenium+Python3之:多线程进行跨浏览器测试
- 从产业链角度,来深度剖析智能家居
- 图层的混合模式全解析-Photoshop照片处理叠图基础教程
- android 调音器,节拍器源码,Best Metronome And Tuner