class B derives from class A,
A has two virtual methods: f1( ) and f2( ). In A::f1( ), it call f2( ).
B override both virtual methods. In B::f1( ), it call A::f1( ). The question is: why B::f2( ) is called rather than A::f2( ).
Thanks!
The output is:Code:#include <stdio.h> class A { public: virtual void f1() { f2(); } public: virtual void f2() { printf("A.f2()\n"); } }; class B : A { public: virtual void f1() { A::f1(); } public: virtual void f2() { printf("B.f2()\n"); } }; int main(int argc, char** argv) { B * b = new B(); b->f1(); delete b; }
>> B.f2()




Reply With Quote