#include <iostream>
#include <string>
using namespace std;
/*---------------------------------
13-5在编译时的静态联编
1) 静态联编:被调函数和调用函数的关系,以及它们内存地址在编译时
都已经确立好,运行时不再发生变化。只需传递参数,执行确定好的函数。
已然确定了调用与被调用的关系,代码在编译与执行时,效果都一样。
2) 动态联编:运行时,需要对各个对象的函数进行追踪
---------------------------------*/
class A
{
public:
int get()
{return 1;}
};
class B:public A
{
public:
int get()
{return 2;}
};
int main()
{
A a;
int one;
one =a.get();
cout<<"a的值是:"<<one<<endl;
B b;
one =b.get();
cout<<"b的值是:"<<one<<endl;
return 0;
}
运行结果:
a的值是:1
b的值是:2
Press any key to continue
C++ 虚函数 5--1 在编译时的静态联编
最新推荐文章于 2020-03-04 21:15:47 发布