diamond-problem

Diamond inheritance (C++)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 06:35:34
问题 I know that having diamond inheritance is considered bad practice. However, I have 2 cases in which I feel that diamond inheritance could fit very nicely. I want to ask, would you recommend me to use diamond inheritance in these cases, or is there another design that could be better. Case 1: I want to create classes that represent different kinds of "Actions" in my system. The actions are classified by several parameters: The action can be "Read" or "Write". The action can be with delay or

Python multiple inheritance name clashes [closed]

亡梦爱人 提交于 2019-12-13 09:48:35
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . 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 ? 回答1: Yes, you can do exactly what you suggest: class D(C, B): a = A.a 来源: https://stackoverflow.com

Diamond problem with only 1 virtual inheritance

淺唱寂寞╮ 提交于 2019-12-12 15:04:00
问题 Does this still solve the diamond problem? class A {}; class B : virtual A {}; class C : A {}; class D : B, C {}; Edit: If not, what is it then? Is it the same as this? class A {}; class B : A {}; class C : A {}; class D : B, C {}; Or is it something even else? 回答1: Diamond problem and ambiguous call to common base members can be best described through the following pictorial equivalent which also give an insight of the memory model Example 1 class A {void foo(){};}; class B :public A {};

Overcoming diamond ambiguity in different way

不问归期 提交于 2019-12-12 09:40:03
问题 I know the diamond problem and method to solve it using virtual base class. I tried to solve diamond problem in a different way but did not succeed. I don't know why. #include <iostream> using namespace std; class A { public: void display() { cout << "successfully printed"; } }; class B: public A { }; class C: private A // display() of A will become private member of C { }; class D: public B, public C // private member display() of C should not be inherited { }; int main() { D d; d.display();

C++ base class function call from last derived in diamond design

人盡茶涼 提交于 2019-12-12 06:09:56
问题 I'm learning C++ and after having read and tested a lot about multiple inheritance, virtual inheritance/methods and diamond design I still have some problems to understand it till the end. I'm in the diamond design pattern, where class B e C inherit virtual public A and D inherits public B, public C : A / \ B C \ / D All classes implement a private variable std::string _message that I initialize with the following string. "class-name instance" Only Class A implements a virtual public display

Solving this specific C++ diamond problem for Qt classes

☆樱花仙子☆ 提交于 2019-12-11 17:25:43
问题 I'm using QT's QQuickFramebufferObject class which inherits from QQuickItem in Qt library. I have the following user-defined class: class OpenGlBufferItem: public QQuickFramebufferObject And I need my OpenGlBufferItem class to also derive from ReactItem . The problem is that ReactItem ultimately derives from QQuickItem too: class ReactItem : public QQuickPaintedItem because QQuickPaintedItem inherits from QQuickItem So we have the following problem: QQuickItem / \ / \ QQuickPaintedItem

Diamond problem

只谈情不闲聊 提交于 2019-12-11 05:45:33
问题 I was going through the diamond problem and thought will work on various scenarios. And this is one among them which I was working on. #include <iostream> using namespace std; class MainBase{ public: int mainbase; MainBase(int i):mainbase(i){} void geta() { cout<<"mainbase"<<mainbase<<endl; } }; class Derived1: public MainBase{ public: int derived1; int mainbase; Derived1(int i):MainBase(i),derived1(i) {mainbase = 1;} public: void getderived1() { cout<<"derived1"<<derived1<<endl; } }; class

Overcoming diamond ambiguity in different way

淺唱寂寞╮ 提交于 2019-12-10 06:31:32
问题 I know the diamond problem and method to solve it using virtual base class. I tried to solve diamond problem in a different way but did not succeed. I don't know why. #include <iostream> using namespace std; class A { public: void display() { cout << "successfully printed"; } }; class B: public A { }; class C: private A // display() of A will become private member of C { }; class D: public B, public C // private member display() of C should not be inherited { }; int main() { D d; d.display();

How does the compiler internally solve the diamond problem in C++?

て烟熏妆下的殇ゞ 提交于 2019-12-08 15:29:39
问题 We know that we can solve the diamond problem using virtual inheritance. For example: 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(); } When we compile this code we will get an ambiguity error.

C++ multiple inheritance

≯℡__Kan透↙ 提交于 2019-12-08 13:14:31
Please don't question the really odd hierarchy of workers in this code here, I have no idea why anyone would want something like this, but I decided to give myself an exercise in Multiple Inheritance, just to be sure I fully understood it. So here's the result. using namespace std; class Employee { protected: string name; public: string getname() { return name; } void setname(string name2) { name = name2; } Employee(string name2) { name = name2; } Employee(){} }; class Manager : public Employee { public: string getname() { return ("Manager" + name); } Manager(string name2) : Employee(name2){}