Questions tagged [diamond-problem]

In object-oriented programming languages with multiple inheritance and knowledge organization, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C.

The diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C.

enter image description here

Example In C++:

/*
The Animal class below corresponds to class 
A in our graphic above
*/
class Animal { /* ... */ }; // base class
{
int weight;

public:

int getWeight() { return weight;};

};

class Tiger : public Animal { /* ... */ };

class Lion : public Animal { /* ... */ }    

class Liger : public Tiger, public Lion { /* ... */ };  


int main( )
{
Liger lg ;

/*COMPILE ERROR, the code below will not get past
any C++ compiler */

int weight = lg.getWeight();  
}
276 questions
-2
votes
1 answer

Why JAVA has a solution for Diamond situation encountered in default interfaces but not for classes?

I was reading about the diamond problem in case of default interfaces, and the documentation says that if there is an interface A with default method m(), which is extended by two other interfaces B & C both having there own default method m(), and…
N Sharma
  • 11
  • 2
-2
votes
2 answers

Unable to get rid of Diamond issue in C++

Please have a look at the code: #include using namespace std; class base1 { public: int x,y; }; class base2 { public: int x, z; }; class derived: virtual public base1,virtual public base2 { public: void…
coder999
  • 15
  • 7
-3
votes
2 answers

What is the problem in this multiple inheritance?

class A: def __init__(self,name): self.name=name class B(A): def __init__(self,name,add): super().__init__(name) self.add = add class C(A): def __init__(self,name,tel): super().__init__(name) …
-3
votes
1 answer

Python multiple inheritance name clashes

I have a question about name clashes in python. If I have something like: class A: a='a' class B(A): a='b' class C(A): a='c' class D(C,B): pass D.a will print c, is there any way to retrieve B.a from D or A.a?
-4
votes
1 answer

Problem with Bisection method on Visual Basic

Here is my code for a bisection method. If I input 4 and 5 the program loops infinitely. There is a problem with it running. Sub TheBisectionMethod1() Dim a, b As Double 'Taking two variables, A and B Console.Write(vbLf & "Input A:…
loco3424
  • 23
  • 2
  • 6
-4
votes
2 answers

Complex multiple inheritance situation

class diagram class A {public: virtual int func();}; class B: virtual public A {}; class C: virtual public A {}; class D: virtual public C {public: virtual int func();}; class E: public B, public D {}; // e is an object of E e->func(); // this will…
1 2 3
18
19