什么是静态联编?请举例 谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/22 08:30:08

静态联编
静态联编含义:
在编译时所进行的这种联编又称静态束定,在编译时就解决了程序中的操作调用与执行该操作代码间的关系。
例7.3.1 一个静态联编的例子。

(动画7_6)
#include<iostream.h>
class point{ private: float x, y;
public:
void setPoint(float I, float j)
{ x=I;
y=j;
}
};
const float pi=3.14159;
class circle:public point
{ private: float radius;
public:
void setRadius( float r)
{ radius =r; }
float area( )
{ return pi*radius*radius;}
};
void mian()
{ point p;
float a=p.area();//调用point类的成员函数
cout<<"the area of the point p is"<<a<<endl;
circle c;
c.setRadius(2.5);
a=c.area(); //调用circle类的成员函数
cout<<"the area of the circle c is"<<a<<endl;
}

程序结果为:
the area of the point p