静态联编

王朝百科·作者佚名  2010-01-02  
宽屏版  字体: |||超大  

静态联编是指联编工作出现在编译连接阶段,这种联编又称早期联编,它解决了程序中的操作调用与执行该操作代码间的关系。

静态联编

静态联编含义:

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

例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;

}

float area( )

{ return 0;}

};

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 is 0

the area of the circle c is 19.634937

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝百科 版权所有