当在基类中把成员函数定义为虚函数后,其派生类中定义的虚函数必须与基类的虚函数同名,参数的类型、顺序、个数必须一一对应。注:析构函数除外举例为。
#include "iostream.h"
class Base
{
public:
protected:
private:
};
class Subclass:public Base
{
public:
};
void test (Base *x)
{
}
void main()
{
}
输出结果为:
first
construct
second
construct in Subclass
calling test(bc)
destructing Base
calling test(sc)
destructing Subclass
destructing Base
end!