Question
Option 2 : Compilation error due to ambiguity
Detailed Solution
सही उत्तर Compilation error due to ambiguity है।
Question:
What is the result of compiling and running the following C++ program? class X { public: int v = 1; }; class Y : public X {}; class Z : public X {}; class W : public Y, public Z {}; int main() { W w; cout << w.v; } / निम्नलिखित C++ प्रोग्राम को कंपाइल और रन करने का परिणाम क्या है?
Correct Answer: Compilation error due to ambiguity
W inherits two separate copies of X (the classic diamond problem), so w.v is ambiguous and the program fails to compile. It can be fixed with virtual inheritance. / W को X की दो अलग-अलग प्रतियाँ विरासत में मिलती हैं (प्रसिद्ध diamond समस्या), इसलिए w.v अस्पष्ट है और प्रोग्राम कंपाइल नहीं होता। virtual inheritance से इसे ठीक किया जा सकता है।