Virtual_Function
来源:互联网 发布:nice软件电脑版 编辑:程序博客网 时间:2024/05/16 12:40
- #include<iostream.h>
- class Father
- {
- public:
- virtual void output()
- {cout<<"Father.output() called"<<endl;}
- };
- class Sun:public Father
- {
- public:
- void output()
- {cout<<"Sun.output() called"<<endl;}
- };
- int main()
- {
- Father father,*pb;
- Sun sun;
- pb=&father;
- pb->output();
- pb=&sun;
- pb->output();
- return 0;
- }
Virutual Function 实现动态绑定