What is virtual inheritance in C++?
2023
What is virtual inheritance in C++?
- A.
C++ technique to enhance multiple inheritance
- B.
C++ technique to ensure that a private member of the base class can be accessed somehow
- C.
C++ technique to avoid multiple copies of the base class into children/derived class
- D.
More than one of the above
- E.
None of the above
Attempted by 103 students.
Show answer & explanation
Correct answer: C
Virtual inheritance in C++ is a technique used to solve the diamond problem in multiple inheritance. When a class inherits from two or more classes that share a common base class, the derived class may end up with multiple copies of the base class. Virtual inheritance ensures that only one instance of the base class is present in the final derived class, preventing redundancy and ambiguity.
हिन्दी उत्तर: C++ में वर्चुअल इनहेरिटेंस एक तकनीक है जो मल्टीपल इनहेरिटेंस में डायमंड समस्या को हल करने के लिए उपयोग की जाती है। जब कोई क्लास दो या अधिक क्लासों से विरासत लेती है जिनका एक सामान्य बेस क्लास होता है, तो डेराइव्ड क्लास में बेस क्लास की एक से अधिक प्रतियाँ हो सकती हैं। वर्चुअल इनहेरिटेंस यह सुनिश्चित करता है कि अंतिम डेराइव्ड क्लास में बेस क्लास की केवल एक ही प्रति होती है, जिससे अतिरिक्तता और अस्पष्टता से बचा जाता है।