虚函数的使用
程序代码:
#include"iostream.h" class base { public: virtual ~base() {} virtual void func() { cout<<"base output!"<<endl; } }; class derived1:public base { public: void func() {cout<<"derived1 output!"<<endl; } }; class derived2:public derived1 { public: void func() {cout<<"derived2 output!"<<endl; } }; void test ( base &rBase) { rBase.func(); }; void main() { base bObj; derived1 d1Obj; derived2 d2Obj; test(bObj); test(d1Obj); test(d2Obj); }
void test ( base &rBase)
这个函数怎么定义在外部了 这里面的base代表什么意思啊