Technical Interview Questions and Answers :: C++
21 / 187
The virtual table(vtable) is a lookup table of functions used to resolve function calls in a dynamic/late binding manner. vPtr is set (automatically) when a class instance is created so that it points to the virtual table for that class. vPtr is inherited by derived classes,
22 / 187
A member function that is declared static has following property,
• A static function can have access to only other static members declared in the same class.
• A static member function can be called using the same class name as follows
class_name:: function_name;
23 / 187
Now Class B
24 / 187
There are 5 forms available, namely
• Single inheritance: A derived class with only one base class
• Multiple inheritance: A derived class with only several base class
• Hierarchical inheritance: The traits one class may be inherited by more than one class
• Multilevel inheritance:
• Hybrid inheritance: it is a combination of multiple and hierarchical inheritance.
25 / 187
Copy constructor is used to declare and initialize an object from another object.
For example, the statement
Integer I2(I1);
Would define the object I2 and at the same time initialize it to the values of I1. another form of this statement is integer I2=I1;
The process of initializing through a copy constructor is known as copy initialization. A copy constructor takes a reference to an object of the same class as itself as an argument.
26 / 187
OR
What is the difference between function overloading and operator overloading? And what are the advantage of it.
function overloading: instead of writing the different functions to perform same actions we write same function name with different number of parameters of different types of parameters it is called function overloading.
advantages of function overloading- improve code
27 / 187
Friend Function:
A friend function can access a class private data, even though it is not a member function of the class. This is useful when one function must have access to two or more unrelated classes and when an overloaded operator must use, on its left side, a value of a class other than one of which it is a member. Friends are also used to facilitate functional notation.
Friend Class:
It is possible to grant a non-member function access to the private members of a class by using a friend. A friend function has access to all private and protected members of the class for which it is a friend.
28 / 187
No Discussion on this question yet!
29 / 187
No Discussion on this question yet!
30 / 187
OR
What will the sizeof empty Class ?
No Discussion on this question yet!