How does the Virtual Differs in C++ and c#? basically i wanted to know is there any difference in the way Vtable is represented in C# and c++? Also is there any difference in the way the compiler creates the V Table in C# and c++?
Basically the interviewer wanted to know how does the compiler behaviour differrs for virtual functions in case of C# and c++.
I have answered the question mentioning there might be no difference in VTABLE expect that there is no Virtual Destructor in c#.
Who said anything about v-tables? Why are you assuming their existence?
The main difference (with relation to the syntax) is that in C++ the derived class doesn't have to know that the function is declared virtual
in the ancestor class, and in C# you must use the override
keyword.
You can call virtual functions in the constructor in C# (and get the expected behavior of calling through the virtual dispatch mechanism) but not in C++.
Though it is not recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With