源程序:
#include <iostream>
using namespace std;
class Based
{
public:
Based()
{
cout<<"Based构造函数\n";
fun();
}
virtual void fun()
{
cout<<"Base::fun()函数\n";
}
};
class Derived:public Based
{
public:
Derived()
{
cout<<"Derived构造函数\n";
fun();
}
void fun()
{
cout<<"Derived::fun()函数\n";
}
};
void main()
{
Derived d;
}
运行结果 :