#include <iostream>
using namespace std;
class Father
{
public:
Father() { A(); }
void virtual A() { cout<<"Father::A()"<<endl; }
void B() { cout<<"Father::B()"<<endl; A();}
};
class Son : public Father
{
public:
void A() { cout<<"Son::A()"<<endl; }
void B() { cout<<"Son::B()"<<endl; }
};
int main()
{
Father f;//father::A
Son s;//father::a!!!
Father *pf=&s;
pf->A();
pf->B();
s.A();//son::a
s.B();//son::b
}
关注到如果虚函数是在Father()的构造函数中,是不体现虚特性的,而在其它地方是体现的,比如关注void B()中的A()