- #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 实现动态绑定