---
title: "Ambiguity in multiple inheritance"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:ambiguity-multiple-inheritance"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/ambiguity-multiple-inheritance
site: BCT Engineering
---

# Ambiguity in multiple inheritance

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2068 Baisakh, 2+6 marks
- Video: [Multiple Inheritance in C++ with Ambiguity & Resolution | C++ programming for Beginners](https://www.youtube.com/watch?v=3XUXSiC-hPE) — Simple Snippets
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/ambiguity-multiple-inheritance
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

Explain the case of ambiguity in inheritance. Write a program that shows ambiguity in multiple inheritance.

## Short answer

Ambiguity arises when two base classes have identically named members; the compiler cannot resolve which to use. Example: Child inherits Father and Mother, both with show(). Calling c.show() is ambiguous; use c.Father::show() to resolve.

## Answer

#### Ambiguity in inheritance
Ambiguity arises when the compiler finds more than one possible meaning for a name and cannot choose. In multiple inheritance, if two base classes have a member (data or function) with the same name and the derived class does not define its own, a call such as `obj.show()` is ambiguous. A second case is the diamond problem, where the final class has two copies of a common grandparent.

It is resolved with the scope resolution operator (`obj.A::show()`), by redefining the member in the derived class, or by using a virtual base class for the diamond case.

#### Program showing ambiguity

```cpp
#include <iostream>
using namespace std;

class Father {
public:
    void show() { cout << "Father's show()" << endl; }
};

class Mother {
public:
    void show() { cout << "Mother's show()" << endl; }
};

class Child : public Father, public Mother {
};

int main() {
    Child c;
    // c.show();       // ERROR: reference to 'show' is ambiguous
    c.Father::show();  // resolved using scope resolution operator
    c.Mother::show();
    return 0;
}
```

If the commented line `c.show();` is enabled, the compiler gives an error like `request for member 'show' is ambiguous`, since both `Father::show()` and `Mother::show()` are equally valid.

**Output (after resolution):**

```text
Father's show()
Mother's show()
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. When does c.show() become ambiguous in multiple inheritance?
   A. When both base classes have show() and the derived class does not define its own
   B. When show() is declared private in the derived class
   C. When show() is declared in only one base class
   D. When the derived class is declared public
   Answer: A. Two bases with the same member name and no redefinition in the derived class leaves the compiler unable to choose. (Key point: Cause of ambiguity)

2. Which call resolves the ambiguity in the program to run Father's version?
   A. c->Father.show()
   B. Father(c).show()
   C. c.Father::show()
   D. c.show(Father)
   Answer: C. The scope resolution operator names the base class explicitly: c.Father::show(). (Key point: Resolving ambiguity)

3. What is the diamond problem and its fix?
   A. The grandparent has no constructor; use a pure virtual function
   B. Two derived classes cannot share a base; use private derivation
   C. The derived class has two copies of a common grandparent; use a virtual base class
   D. A class inherits from itself; use a friend function
   Answer: C. The final class gets two copies of the common grandparent, which a virtual base class reduces to one. (Key point: Diamond problem)

## Related in Object Oriented Programming

- [Constructor and destructor order, multilevel inheritance](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Actor-order-multilevel) — Object Oriented Programming, chapter 6, asked 2×
- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6

## Related in other subjects

- [Correct program: case array and average](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Acorrect-program-case-array) — Computer Programming, chapter 3
- [Bidding preparation, ambiguity, percentage contract](https://www.bctengineer.com/question.md?key=semester_8%2Fengineering_professional_practice%3Abidding-notice-percentage-contract) — Engineering Professional Practice, chapter 4
- [Convert case based on first character](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aswap-case-first-char-word) — Computer Programming, chapter 7
