为什么|error: passing 'const Fraction' as 'this' argument of 'int Fraction::getson()' discards qualifiers [-fpermissive]|会这样,而我把getson()改成了int getson() const{return son;}就没有错误了。不可以通过常量指针a改变变量,那为什么一定要把this指针也弄成常量指针呢?很困惑呀!大神们,帮帮我!,
#include<iostream>
#include<fstream>
using namespace std;
class Fraction{
private:
int son;
int mum;
public:
Fraction():son(1),mum(1){};
int getson(){return son;}
void co(const Fraction &a)
{
cout<<a.getson()<<endl;
}
int main()
{
Fraction a;
cout<<co(a);
return 0;
}