+ 5
What is the output of this code?
I recently came across this Brainstorming puzzle https://code.sololearn.com/c6f0IInZ0AWy/?ref=app
9 Respostas
+ 4
needed an explanation 🙄
+ 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
+ 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/
+ 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 !😊
+ 2
bbbbbb
+ 1
B