发一下牢骚和主题无关:
如果子类中有虚函数则先将子类的虚函数入栈,然后是父类的虚函数,如果子类写重了父类的虚函数,则入栈的是子类写重的函数,即写重的子类的函数替换对应的父类的虚函数。
如://A.h
#ifndef __A_H
#define __A_H
#include <iostream>
using namespace std;
class A{
//private:
virtual void f()
{
cout<<"A::f"<<endl;
}
virtual void g(){
cout<<"A::g"<<endl;
};
#endif
//B.h
每日一道理
天又快黑了,这座忙碌的城市又将入睡,让这劳累的“身躯”暂别白日的辛勤,让它入睡,陪伴着城市中的人们进入梦乡。当空的弯月正深情地注视着这座城市与城市中的人们,看着家家户户的灯渐渐熄灭,它在床头悄悄奏响“明月曲”……
#ifndef __B_H
#define __B_H
//#include <iostream>
#include "A.h"
class B:public A{
void d()
cout<<"B::d"<<endl;
virtual void h()
cout<<"B::h"<<endl;
#endif
//main.cpp