multiple-inheritance

Virtual inheritance in C++

隐身守侯 提交于 2019-11-27 23:38:51
I found this in a website while reading about virtual inheritance in c++ When multiple inheritance is used, it is sometimes necessary to use virtual inheritance. A good example for this is the standard iostream class hierarchy: //Note: this is a simplified description of iostream classes class ostream: virtual public ios { /*..*/ } class istream: virtual public ios { /*..*/ } class iostream : public istream, public ostream { /*..*/ } //a single ios inherited How does C++ ensure that only a single instance of a virtual member exists, regardless of the number of classes derived from it? C++ uses

Class extending more than one class Java?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 22:46:53
I know that a class can implement more than one interface, but is it possible to extend more than one class? For example I want my class to extend both TransformGroup and a class I created. Is this possible in Java? Both statements class X extends TransformGroup extends Y and class X extends TransformGroup, Y receive an error. And if it is not possible, why? TransformGroup extends Group but I guess it also extends Node since it inherits fields from Node and it can be passed where a Node object is required. Also, like all classes in Java, they extend Object class. So why wouldn't it be possible

Multiple inheritance metaclass conflict

拟墨画扇 提交于 2019-11-27 22:28:58
I need a double inheritance for a class. I tried several syntaxes but I don't understand the concept of metaclass. from PyQt5.QtGui import QStandardItem from configparser import ConfigParser class FinalClass(ConfigParser, QStandardItem): def __init__(self, param): ConfigParser.__init__(self) QStandardItem.__init__(self) The problem in your case is that the classes you try to inherit from have different metaclasses: >>> type(QStandardItem) <class 'sip.wrappertype'> >>> type(ConfigParser) <class 'abc.ABCMeta'> Therefore python can't decide which should be the metaclass for the newly created

Why can't I inherit from dict AND Exception in Python?

邮差的信 提交于 2019-11-27 22:04:27
I got the following class : class ConstraintFailureSet(dict, Exception) : """ Container for constraint failures. It act as a constraint failure itself but can contain other constraint failures that can be accessed with a dict syntax. """ def __init__(self, **failures) : dict.__init__(self, failures) Exception.__init__(self) print isinstance(ConstraintFailureSet(), Exception) True raise ConstraintFailureSet() TypeError: exceptions must be classes, instances, or strings (deprecated), not ConstraintFailureSet What the heck ? And the worst is that I can't try super() since Exception are old based

Resolving metaclass conflicts

隐身守侯 提交于 2019-11-27 21:50:14
I need to create a class that uses a different base class depending on some condition. With some classes I get the infamous: TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases One example is sqlite3 , here is a short example you can even use in the interpreter: >>> import sqlite3 >>> x = type('x', (sqlite3,), {}) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Use of enable_shared_from_this with multiple inheritance

与世无争的帅哥 提交于 2019-11-27 20:25:35
问题 BI am using enable_shared_from_this in my code, and I am not sure if its usage is correct. This is the code: class A: public std::enable_shared_from_this<A> { public: void foo1() { auto ptr = shared_from_this(); } }; class B:public std::enable_shared_from_this<B> { public: void foo2() { auto ptr = shared_from_this(); } }; class C:public std::enable_shared_from_this<C> { public: void foo3() { auto ptr = shared_from_this(); } }; class D: public A, public B, public C { public: void foo() { auto

Virtual Inheritance: Error: no unique final overrider

非 Y 不嫁゛ 提交于 2019-11-27 20:11:32
I know virtual inheritance is covered here before and before asking this question I went through the detail of the virtual inheritance and went through the details of a similar problem like the followings: multiple-diamond-inheritance-compiles-without-virtual-but-doesnt-with and why does gcc give me an error - final overrider My problem is slightly different as I am not using pure virtual function and explicitly using virtual inheritance to have one unique 'Base' class. The hierarchy is as follows: Base /\ / \ Der1 Der2 \ / Der3 I know about the dreadful diamond on derivation issue and that's

Two interfaces with same method signature implemented in Java class

梦想的初衷 提交于 2019-11-27 19:50:18
I have two Java interfaces and one implementing class. (I have used Eclipse to run the program directly, and I did not try to check any compiler warning et cetera by explicitly compiling from the command line.) Why do they run without problem? Why does Java allow this, even when it satisfies the "contract" of both interfaces but create ambiguity in implementing class? Updated the example. public interface CassettePlayer { void play(); } public interface DVDPlayer { void play(); } public class CarPlayer implements CassettePlayer,DVDPlayer{ @Override public void play() { System.out.println("This

Multiple inheritance metaclass conflict

时光怂恿深爱的人放手 提交于 2019-11-27 19:10:34
问题 I need a double inheritance for a class. I tried several syntaxes but I don't understand the concept of metaclass. from PyQt5.QtGui import QStandardItem from configparser import ConfigParser class FinalClass(ConfigParser, QStandardItem): def __init__(self, param): ConfigParser.__init__(self) QStandardItem.__init__(self) 回答1: The problem in your case is that the classes you try to inherit from have different metaclasses: >>> type(QStandardItem) <class 'sip.wrappertype'> >>> type(ConfigParser)

Elegant alternatives to the weird multiple inheritance

一曲冷凌霜 提交于 2019-11-27 18:54:23
问题 I can not say that this is a question, but more of an opinion request and I am sure many others could benefit from clarifying this issue. Here is my practical case: I have an abstract class called DataExchangeService and a lot of sub-classes that extend this one (this is the base CONTROLLER class in my MVC Framework). The administration modules that handle data definiton (Users,Types,Sections etc) they all have the add,edit,delete,list methods with 100% similarity in most cases. I know that