#include "stdafx.h"
#include <iostream.h>class base
{
public:
  virtual void f1()
  {
  cout<<"f1 function of base"<<endl;
  }
  virtual void f2()
  {
   cout<<"f2 function of base"<<endl;
  }
  virtual void f3()
  {
  cout<<"f3 function of base"<<endl;}
  void f4()
  {
  cout<<"f4 function of base"<<endl;
  }
};
class derive:public base
{
void f1()
{
 cout<<"f1 function of derive"<<endl;
}
void f2(int x)
{
 cout<<"f2 function of derive"<<endl;
}
virtual void f3()
{
 cout<<"f3 function of base"<<endl;
};
void f4()
{
cout<<"f4 function of base"<<endl;
}
};
void main()
{
base obj1,*p;
derive obj2;
p=&obj1;
p->f1();
p->f2();
p->f3();
p=&obj2;
p->f1();
p->f2();
p->f4();
}
为什么程序输出为:
f1 function of base
f2 function of base
f3 function of base
f1 function of derive
f2 function of base
f4 function of base
最后两行为什么会是这样?