#include <iostream.h>
class base{
public:
base( ){cout<<”the constructor of base”<<endl;
clone( );}
virtual void clone( ){cout<<”the clone function of base”<<endl;}
};
class derive:public base{
public:
derive( ){cout<<”the constructor of derive”<<endl;}
void clone( ){cout<<”the clone function of derive”<<endl;}
};
void main(void)
{derive obj;
base *ptr=&obj;
ptr->clone( );
}
结果:
the constructor of base
the clone function of base //为什么执行基类的clone( )?
The constructor of derive
The clone functionof derive