📄 demo_6_const_object_3.cpp
字号:
//************************************************
# include <iostream.h>
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);
//只能用常成员函数访问常对象的数据成员
//若数据成员声明为mutable,则允许常成员函数修改常对象数据成员的值
stud.display();
stud.change(101,88.5);
stud.display();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -