now the output is cc When i take virtual from the class A the output is bc. why does it happen ? https://code.sololearn.com/cy4RgGt7HDRt/?ref=app
Ketan Lalcheta thanks a lot . i am learning it newly. thanks in advance .
Borislav Kalinski when i use virtual pointer refers to derived class ? i got it thanks .
Borislav Kalinski no. i can understand everything. thanks anyway
Borislav Kalinski writing f as method in class A . without virtual .
yeap i knew it . i meant why was the output different when i use it . Borislav Kalinski
Because of pointer when you use it you call f from base class not f from divired class.
Sorry for my bad explanation if i rearly helped no problem.
What do you mean by taking virtual from class A?
Virtual is used if you want to modify the method in devired class.
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 ☺️😊