【发布时间】:2020-11-04 08:06:15
【问题描述】:
“this discards qualifiers”,是什么意思?
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
class b
{
public:
void show( b &ob)
{
//this =ob;
cout<<"show";
}
};
int main()
{
b const ob;
b ob1;
ob.show(ob1);
// your code goes here
return 0;
}
prog.cpp: In function ‘int main()’:
prog.cpp:23:14: error: passing ‘const b’ as ‘this’ argument discards qualifiers [-fpermissive]
ob.show(ob1);
^
【问题讨论】:
-
您正试图在 const qualifoed 对象上调用非 const 函数 (b)
-
@sumitkumar 太棒了!请考虑accepting我的回答。您的问题仍列为未回答。
-
@Ann Zen,当然但是我仍在等待最佳答案。暂时,我已经对答案投了赞成票。
标签: c++