Thursday, November 27, 2003

Re: Polymorphism

I think Mohn's posting is correct. In your example Dinesh, only the base class has a virtual function and therefore pr only figures in the v-table of base. pr wouldn't figure in the v-table of derv (if it had one) at all since it's not virtual in derv. So a question of looking up derv's v-table doesn't arise. A call to a function using pointer of base class (even if it actually points to a derived class object) always goes to the base class. And only IF the function figures in the v-table, the corresponding function of the derived class is called.

Hope this helps.

No comments: