📄 动态绑定(点类和矩形类)1.txt
字号:
#include <iostream.h>
class Point
{
public:
Point(double i,double j) {x=i;y=j;}
virtual double Area() const {return 0.0;}
private:
double x,y;
};
class Rectangle:public Point
{
public:
Rectangle(double i,double j,double k,double l);
virtual double Area() const {return w*h;}
private:
double w,h;
};
Rectangle::Rectangle(double i,double j,double k,double l):Point(i,j)
{
w=k;h=l;
}
void fun(Point &s)
{
cout<<"fun: "<<s.Area()<<endl;
}
void fun1(Point s)
{
cout<<"fun1: "<<s.Area()<<endl;
}
void fun2(Point *p)
{
cout<<"fun2: "<<p->Area()<<endl;
}
void main()
{
Rectangle rec(3.0,5.2,15.0,25.0);
fun(rec);
fun1(rec);
fun2(&rec);
}
fun: 375
fun1: 0
fun2: 375
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -