在类的成员函数后可以加const,表示该函数不会修改成员变量的值(有时这个const是必须加的,不加编译器会报错)
class Person
{
int a;
int b;
public:
void f(int& ,int&)const;
};
void Person::f(int &a1,int &b1)const
{
a1++;
b1++;
}
int main()
{
int a=0,b=2;
Person p;
p.f(a,b);
cout<<a<<" "<<b<<endl;
return 0;
}