+ 1
Overloading virtual function
class A{public: void f(){cout<<"A";}}; class B:public A{public: void f(){cout<<"B";}}; class C:public B{public: void f(){cout<<"C";}}; int main(){B *p = new C; p->f();} prints B. but when virtual void f() is declared in place of void f() in A, all else the same, prints C. would appreciate insight into this matter..thx
1 Resposta
+ 1
https://stackoverflow.com/questions/2391679/why-do-we-need-virtual-functions-in-c
acc to the discussions here..seems like virtual keyword enables runtime(question here) polymorphism