answersLogoWhite

0


Best Answer

Use virtual base classes. It is best if the common base class has no member variables and all member methods are pure-virtual. The multiple-inheritance class must provide all the implementation for the pure-virtual methods, even if the direct bass classes also provide their own implementations.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

It is not clear what "multiple inheritance" means but ambiguities in wills are resolved in court on an action to construe the will. There are two types of ambiguities. Ones that arise from ambiguous language in the will and ones that arise from facts outside the will. The court will take evidence of the facts relevant to the ambiguity to resolve it. The idea is to ascertain the decedent's probable intent when making the will in order to clarify the matter.



Hi,

In multiple inheritance the ambiguity arises when same method name is being used by two derived class and furthur derivation from these two base classes. This is called Diamond problem. In order to solve this issue virtual base class concept is being used where base class is virtual to derived ones. For example, u have one base class A, and two derived class B and C, Now one more derived class from B and C is D. In this situation 2 subobject of A will be created (one from B and another from C).In order to avoid such situations we use virtual base class.

class A
{

public:
A(int a)
{
cout<<"Base class A"<}

}

class B:public class A
{
public:
B(int b,int a):A(int a)
{
cout<<"Derived class B"<}

}
class C:public class A
{
public:
C(int c,int a):A(int a)
{
cout<<"Derived class C"<}

}

class D:public class C,public class B
{
public:
D(int d,int c,int b):C(int c,int a),B(int b,int a)
{

}

}

main()
{
D d(1,2,3);
}

Output:
Base class A : 3
Derived class C : 1

Base class A : 3
Derived class B: 2


This issue is being solved by making class A as virtual and then output will be

Base class A : 3
Derived class C : 1
Derived class B: 2
This answer is:
User Avatar

User Avatar

Wiki User

11y ago

There is no such thing. Ambiguity occurs in multiple inheritance where two or more base classes share a common member name.

In the following example, two base classes share common public member name, GetData(). The derived class inherits both, but you cannot call derived::GetData() because the compiler cannot tell which method to actually call.

#include <iostream>

class base1

{

public:

base1(int data=0):m_data(data){}

int GetData()const{return(m_data);}

private:

int m_data;

};

class base2

{

public:

base2(int data=0):m_data(data){}

int GetData()const{return(m_data);}

private:

int m_data;

};

class derived : public base1, public base2

{

public:

derived(int data=0):base1(data),base2(data){}

};

int main()

{

derived d(5);

int x = d.GetData(); // Ambiguous!

return( 0 );

}

To remove the ambiguity, you must explicitly call d.base1::GetData() or d.base2::GetData().

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

When you derive classes, ambiguities can result if base and derived classes have members with the same names. Access to a base class member is ambiguous if you use a name or qualified name that does not refer to a unique function or object. The declaration of a member with an ambiguous name in a derived class is not an error. The ambiguity is only flagged as an error if you use the ambiguous member name.

For example, suppose that two classes named A and B both have a member named x, and a class named C inherits from both A and B. An attempt to access x from class C would be ambiguous. You can resolve ambiguity by qualifying a member with its class name using the scope resolution (::) operator.

class B1

{

public:

int i; int j;

void g(int) { }

};

class B2

{

public:

int j;

void g() { }

};

class D : public B1, public B2 {

public:

int i;

};

int main()

{

D dobj;

D *dptr = &dobj;

dptr->i = 5;

// dptr->j = 10;

dptr->B1::j = 10;

// dobj.g();

dobj.B2::g(); }

The statement dptr->j = 10 is ambiguous because the name j appears both in B1 and B2. The statement dobj.g() is ambiguous because the name g appears both in B1 and B2, even though B1::g(int) and B2::g() have different parameters.

The compiler checks for ambiguities at compile time. Because ambiguity checking occurs before access control or type checking, ambiguities may result even if only one of several members with the same name is accessible from the derived class.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Hybrid, or multiple, inheritance in C++ can be ambiguous. To resolve this, you can qualify the name with its class name. For example.

class a {

int z;

...

}

class b {

int z;

...

}

class c : public a, public b {

...

something = z; // ambiguous

something = a::z; // un-ambiguous

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Ambiguity in hybrid, or multiple inheritance is when the same named method or attribute of two different classes is inherited by one class. Example: a is a member of b and c. If you create a d that inherits from both b and c, d will contain two different a's, one from b and one from c. Unless you use scope resolution syntax, a reference to a within the context of d will be ambiguous. This would be in the form, for instance, of b::a, and c::a, instead of just a.

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

In languages like C, there might be ambiguity because of same method names in more than one parent class.

This is the main reason why Java does not support direct multiple inheritance.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

You dont because Java does not support direct Multiple Inheritance

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

No there is no ambiguity in single inheritance

This answer is:
User Avatar

User Avatar

Anonymous

Lvl 1
3y ago

c

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you resolve ambiguity in multiple inheritance?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Give the structure of multiple inheritance?

Java does not support multiple inheritance. It is done with the help of interfaces in java. a class can implement n number of interfaces, thus showing multiple inheritance. but a class cannot extend multiple classes in java.


How can you write multiple inheritance program in java?

Java does not support direct multiple inheritance. You can implement partial multiple inheritance using interfaces. ex: public class ExMultInherit implements interface1, interface2, interface 3 { ... .... ...... }


Drawbacks of multiple inheritance in c plus plus?

There are no drawbacks to multiple inheritance if multiple inheritance is precisely what is required to achieve your goal. If there are any drawbacks then it is only because of poor design, not multiple inheritance itself. For instance, when designing classes to simulate vehicles, an amphibious vehicle would inherit the properties of both an off-road vehicle and a marine vehicle, therefore multiple inheritance would be an appropriate usage.


Does hybrid inheritance consist of ANY two types of inheritance?

There are only two types of inheritance to begin with: single inheritance and multiple inheritance. Since they are mutually exclusive there is no such thing as hybrid inheritance.


How ploymorphism and inheritance is different from that in Java and c plus plus?

C++ allows multiple inheritance while Java does not. In my opinion, multiple inheritance is not useful because it can get very confusing very quick. For polymorphism, C++ does early binding by default, while Java does late binding by default. Late binding is more useful than early binding.

Related questions

What is ambiguity in multiple inheritance?

Java does not support multiple inheritance


Why multiple inheritance is not possible with respect to class in java?

compiler will confuse when two super class has same method name. The above is correct, and it's a DESIGN decision made by the originator of Java, James Gosling. That is, Gosling recognized that true Multiple Inheritance has a certain amount of ambiguity involved, and mistakes around that ambiguity are easy to make and hard to detect. So, Gosling decided that Java should not allow Multiple Inheritance at all. Almost all of the functionality of class-based Multiple Inheritance can be obtained via Interfaces. Additionally, not supporting Multiple Inheritance greatly simplifies the compiler requirements, and makes the JVM faster and easier to create.


Different types of inheritances?

Single Inheritance Multiple Inheritance Multilevel Inheritance


Why is multiple inheritance not provided in Java?

One of the main reasons for creating Java was to address the problems of C++. One such problem was multiple inheritance, which was prone to ambiguity when a class inherited from two separate classes which shared a function with an identical definition. The designers of Java decided to eliminate this problem altogether by only allowing a class to inherit from a single other concrete class.


What type of inheritance pattern are these rabbits likely displaying?

Types of dominance, multiple alleles, sex linked inheritance, polygenic inheritance and maternal inheritance.


Give the structure of multiple inheritance?

Java does not support multiple inheritance. It is done with the help of interfaces in java. a class can implement n number of interfaces, thus showing multiple inheritance. but a class cannot extend multiple classes in java.


What kind of inheritance is not allowed in java?

Java does not allow the multiple inheritance of concrete classes, though it does allow a "hybrid" inheritance of one concrete class and multiple interfaces.


How can you write multiple inheritance program in java?

Java does not support direct multiple inheritance. You can implement partial multiple inheritance using interfaces. ex: public class ExMultInherit implements interface1, interface2, interface 3 { ... .... ...... }


Drawbacks of multiple inheritance in c plus plus?

There are no drawbacks to multiple inheritance if multiple inheritance is precisely what is required to achieve your goal. If there are any drawbacks then it is only because of poor design, not multiple inheritance itself. For instance, when designing classes to simulate vehicles, an amphibious vehicle would inherit the properties of both an off-road vehicle and a marine vehicle, therefore multiple inheritance would be an appropriate usage.


Why is multiple inheritance not possible in C?

C is not object-oriented -- you can't even use single inheritance let alone multiple inheritance.


What is problem in multiple inheritance?

Java does not support direct multiple Inheritance. Harder to implement, not every language support it: C++ does, Java does not.


Does hybrid inheritance consist of ANY two types of inheritance?

There are only two types of inheritance to begin with: single inheritance and multiple inheritance. Since they are mutually exclusive there is no such thing as hybrid inheritance.