作业帮 > 综合 > 作业

关于这个VC++的问题

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 03:26:47
关于这个VC++的问题
#include
using namespace std;
class Point()
{
public:
Point(int x1,int y1){x=x1;y=y1;}
int area()const{return 0;}
private:
int x,y;
};
class Rect:public Point
{
public:
Rect(int x1,int y1,int u1,int w1):Point(x1,y1)
{
u=u1;w=w1;
}
int area()const{return u*w;}
private:
int u,w;
}
其中.
int area()const{return u*w;}中的CONST起的是什么作用呢?
const 放在函数末尾,常函数,通常只能修饰成员函数
用来限制,不能直接修改类的成员变量,如果你修改了会报编译错误
但是如果你通过地址等间接修改它是检查不出来的,因为它只做编译期检查