菜鸟问题请教
leboc 2008-10-23 11:10:13 #include <iostream>
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
void change(int n,float s) const{num=n;score=s;}
void display() const {cout<<num<<" "<<score<<endl;}
private:
mutable int num;
mutable float score;
};
int main()
{const Student stud(101,78.5);
void fun(Student &);
fun(stud); //这里,不允许const类型的stud 转换成&stu;
return 0;
}
void const fun(Student &stu)
{
stu.display();
stu.change(101,80.5);
stu.display();
}
请问除了去掉const外,还有什么办法可以用fun?