10 Answers
New AnswerBorislav Kalinski when i use virtual pointer refers to derived class ? i got it thanks .
yeap i knew it . i meant why was the output different when i use it . Borislav Kalinski
Fidan Rli B* P = & c; This means you have a pointer of Class B which is pointing to object of Class C... B class method is called by p->f() as p is nothing but pointer of Class B.... this is the normal scenario... if we put virtual keyword, compiler checks in details (using vpointer and vtable) and decides to go with class c method as p is pointing to class c object... I would suggest you to refer any article on polymorphism to understand this in detail... feel free to ask if anything you could not understand from any article you gonna read on this... Happy learning ☺️😊
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message