What is the output of this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the output of this code?

I recently came across this Brainstorming puzzle https://code.sololearn.com/c6f0IInZ0AWy/?ref=app

2nd Jul 2019, 5:52 PM
Aditya
Aditya - avatar
6 Answers
+ 4
needed an explanation 🙄
2nd Jul 2019, 6:11 PM
Aditya
Aditya - avatar
+ 3
~ swim ~ well then I guess I must have missed some points.. I really need to refresh my c++ concepts😅. Thanks for clearing out the topic, I will study it further
3rd Jul 2019, 6:20 AM
Madhav
Madhav - avatar
+ 2
Maggie it's because B derives public function of A i.e mehod() but since B also have a same named function that overrides it thus for such cases virtual functions are used . ! read this for more info on it : https://www.geeksforgeeks.org/virtual-function-cpp/
2nd Jul 2019, 6:19 PM
Madhav
Madhav - avatar
+ 2
~ swim ~ as you mentioned in your answers the compiler will choose the nearest in hierarchy and thanks to point that out, that when value is passed it works just as usual . my point was for why C is acessing B's function not A true that's what I meant by overriding and I mentioned virtual functions in case we want to use both the functions from both classes. Since virtual functions ensure that the correct function is called for an object, regardless of the type of reference i.e(by referring address or pointer) used for function call. I hope that this helps !😊
3rd Jul 2019, 5:01 AM
Madhav
Madhav - avatar
+ 2
bbbbbb
5th Jul 2019, 6:26 AM
XxxxxxxxxxX
XxxxxxxxxxX - avatar
+ 1
B
2nd Jul 2019, 6:11 PM
Vick
Vick - avatar