Google News
logo
CPP - Quiz(MCQ)
What is virtual inheritance in C++?
A)
C++ technique to enhance multiple inheritance
B)
C++ technique to avoid multiple inheritances of classes
C)
C++ technique to avoid multiple copies of the base class into children/derived class
D)
C++ technique to ensure that a private member of the base class can be accessed somehow

Correct Answer :   C++ technique to avoid multiple copies of the base class into children/derived class


Explanation :

Virtual inheritance is a C++ technique that ensures only one copy of a base class's member variables are inherited by grandchild derived classes. Without virtual inheritance, if two classes B and C inherit from a class A, and a class D inherits from both B and C, then D will contain two copies of A's member variables: one via B, and one via C. These will be accessible independently, using scope resolution.
 
Instead, if classes B and C inherit virtually from class A, then objects of class D will contain only one set of the member variables from class A. etc,. (Refer Wikipedia for more info..)

Advertisement