Recently I attended an interview. The interviewer asked me to explain virtual function mechanism in C++. I explained using VPTR and VTABLE. I explained in detail how VPTR and VTABLE are used to achieve run time polymorphism.
While I was explaining how the compiler introduces hidden code to fetch VPTR from the class, get function address from VTABLE and call is resolved. But he was not satisfied with the answer. He asked me detail of hidden code? What exactly does a compiler do? If a compiler is doing everything for you then what is the use of developer?
I searched for details of the role of a compiler for virtual functions. Regarding the hidden code. But still not clear about the question.
Please, any help or pointers?