multiple-inheritance

python multiple inheritance passing arguments to constructors using super

旧街凉风 提交于 2019-11-30 10:54:50
问题 Consider the following snippet of python code class A(object): def __init__(self, a): self.a = a class B(A): def __init__(self, a, b): super(B, self).__init__(a) self.b = b class C(A): def __init__(self, a, c): super(C, self).__init__(a) self.c = c class D(B, C): def __init__(self, a, b, c, d): #super(D,self).__init__(a, b, c) ??? self.d = d I am wondering how can I pass a , b and c to corresponding base classes' constructors. 回答1: Well, when dealing with multiple inheritance in general, your

bad weak pointer when base and derived class both inherit from boost::enable_shared_from_this

谁说我不能喝 提交于 2019-11-30 10:06:59
I have a base class which derives from boost::enable_shared_from_this, and then another class which derives from both the base class and boost::enable_shared_from_this: #include <boost/enable_shared_from_this.hpp> #include <boost/shared_ptr.hpp> using namespace boost; class A : public enable_shared_from_this<A> { }; class B : public A , public enable_shared_from_this<B> { public: using enable_shared_from_this<B>::shared_from_this; }; int main() { shared_ptr<B> b = shared_ptr<B>(new B()); shared_ptr<B> b_ = b->shared_from_this(); return 0; } This compiles but at runtime it gives terminate

C++ Multiple Virtual Inheritance vs. COM

不问归期 提交于 2019-11-30 09:50:54
The net is overflowing with explanations of the "dreaded diamond problem" . So is StackOverflow. I think I understand that bit, but I fail to translate that knowledge into comprehending something similar yet different. My question begins as a pure C++ question, but the answer might well branch over into MS-COM specifics. The general problem question goes: class Base { /* pure virtual stuff */ }; class Der1 : Base /* Non-virtual! */ { /* pure virtual stuff */ }; class Der2 : Base /* Non-virtual! */ { /* pure virtual stuff */ }; class Join : virtual Der1, virtual Der2 { /* implementation stuff *

__bases__ doesn't work! What's next?

霸气de小男生 提交于 2019-11-30 09:13:59
The following code doesn't work in Python 3.x, but it used to work with old-style classes: class Extender: def extension(self): print("Some work...") class Base: pass Base.__bases__ += (Extender,) Base().extension() Question is simple: How can I add dynamically (at runtime) a super class to a class in Python 3.x? But I'm ready the answer will be hard! ) Mykola Kharechko As for me it is impossible. But you can create new class dynamically: class Extender(object): def extension(self): print("Some work...") class Base(object): pass Base = type('Base', (Base, Extender, object), {}) Base()

Multiple Inheritance: What's a good example?

雨燕双飞 提交于 2019-11-30 09:12:51
I'm trying to find a good example for the use of multiple inheritance what cannot be done with normal interfaces. I think it's pretty hard to find such an example which cannot be modeled in another way. Edit: I mean, can someone name me a good real-world example of when you NEED to use multiple inheritance to implement this example as clean as possible. And it should not make use of multiple interfaces, just the way you can inherit multiple classes in C++. The following is a classic: class Animal { public: virtual void eat(); }; class Mammal : public Animal { public: virtual void breathe(); };

Consequences of changing inheritance to virtual?

[亡魂溺海] 提交于 2019-11-30 09:05:47
I'm working on a huge project that I didn't start. My task is to add some additional functionality to what already is there. I'm in a situation where I have to use virtual inheritance because I have a diamond model. The situation is depicted in the following illustration: Base class / \ / \ My new class A class that was there before (OldClass) \ / \ / \ / \ / My other new class For this to work, both the classes in the middle have to inherit from the base through public virtual instead of just public . So: class OldClass: public BaseClass {} has to become: class OldClass: public virtual

Sqlalchemy: avoiding multiple inheritance and having abstract base class

若如初见. 提交于 2019-11-30 08:35:54
So I have a bunch of tables using SQLAlchemy that are modelled as objects which inherit from the result to a call to declarative_base() . Ie: Base = declarative_base() class Table1(Base): # __tablename__ & such here class Table2(Base): # __tablename__ & such here Etc. I then wanted to have some common functionality available to each of my DB table classes, the easiest way to do this according to the docs is to just do multiple inheritance: Base = declarative_base() class CommonRoutines(object): @classmethod def somecommonaction(cls): # body here class Table1(CommonRoutines, Base): # _

Input and Output Stream Pipe in Java

北城余情 提交于 2019-11-30 08:25:32
问题 Does anyone have any good suggestions for creating a Pipe object in Java which is both an InputStream and and OutputStream since Java does not have multiple inheritance and both of the streams are abstract classes instead of interfaces? The underlying need is to have a single object that can be passed to things which need either an InputStream or an OutputStream to pipe output from one thread to input for another. 回答1: It seems the point of this question is being missed. If I understand you

Exception multiple inheritance

﹥>﹥吖頭↗ 提交于 2019-11-30 07:36:21
问题 I have the problem with mixing exceptions and multiple inheritance. Basically I have this code: #include <exception> #include <stdexcept> #include <iostream> class A : public std::exception { public: virtual ~A() noexcept {}; }; class B : public A, public std::runtime_error { public: B() : A{}, std::runtime_error{""} { } }; int main() { try { throw B{}; } catch (const std::exception& error) { // this catch doesn't work std::clog << "Caught!" << std::endl; } } What I need is to modify it so

CodeIgniter Extending Multiple Controllers?

痞子三分冷 提交于 2019-11-30 07:22:11
Can't find a way to do this, possibly because there is another way to do this? Some of my controllers extend AdminLayout and some of them extend ModLayout but I also need these pages to extend a LoggedIn Controller. class Profile extends AdminLayout, LoggedIn { However looking into there is no way to do this nicely. Is there a workaround? Assuming that you are using Codeigniter 2, this can be done by putting all you extended controller classes in the same file. In /application/core create a file called MY_Controller.php (don't forget to check the subclass prefix in config.php around line 109)