C++ Qs : virtual functions and function overloading
Interview Answers
Anonymous
Oct 27, 2011
multiplication by 7 = multiplication by (8 - 1)
long 7mul_without_star(int n){
return ((n << 3) - n);
}
3
Anonymous
Oct 27, 2011
virtual function is a function in the parent class that allows to be overridden (allowing for dynamic polymorphism).
with virtual function (in C++) there is a special virtual pointer table that is generated by compiler to track functions ). hence sizeof(class) will be usual size + sizeof(ptr)
if function is not declared virtual and overridden always the function in parent gets called.