C and C++ Interview Questions |
3. What is Pure Virtual Function? Why and when it is used ?
Ans:
The abstract class whose pure virtual method has to be implemented by all the classes which derive on these. Otherwise it would result in a compilation error.
This construct should be used when one wants to ensure that all the derived classes implement the method defined as pure virtual in base class
|
Ex Q1: What is problem with Runtime type identification?
Ans:
The run time type identification comes at a cost of performance penalty. Compiler maintains the class.
|
Ex Q2: Can inline functions have a recursion?
Ans:
No.
Syntax wise It is allowed. But then the function is no longer Inline. As the compiler will never know how deep the recursion is at compilation time.
|
Ex Q3: How Virtual functions call up is maintained?
Ans:
Through Look up tables added by the compile to every class image. This also leads to performance penalty.
|
Ex Q4: How do you link a C++ program to C functions?
Ans:
By using the extern "C" linkage specification around the C function declarations.
Programmers should know about mangled function names and type-safe linkages. Then they should explain how the extern "C" linkage specification statement turns that feature off during compilation so that the linker properly links function calls to C functions.
|
Ex Q5: Name some pure object oriented languages?
Ans:
Ø Smalltalk,
Ø Java,
Ø Eiffel,
Ø Sather. |