http://blog.sina.com.cn/s/blog_466496f30100xp2l.html
rules:
1.如果在父类函数中调用父类的虚函数,且该虚函数在子类中被改写了,那么在把子类指针/引用交给父类指针/引用的时候,在调用父类中的函数,该函数内的虚函数实际上是子类中改写过的。
#include<stdio.h>
class base
{
void a()
{
printf("base a\n");
b(1);
};
virtual void b(int x)
{
printf("base b %d \n",x);
};
};
class ext:public base
{
{
printf("ext b %d \n",x);
};
};
int main()
{
}
result:
[zhliu@sdcsn05 ~]$ test43
base a
ext b 1
base a
ext b 1
base a
base b 1