multiple-inheritance

Django - deleting object, keeping parent?

元气小坏坏 提交于 2020-01-11 08:24:11
问题 I have the following multi-table inheritance situation: from django.db import Models class Partner(models.Model): # this model contains common data for companies and persons code = models.CharField() name = models.CharField() class Person(Partner): # some person-specific data ssn = models.CharField() class Company(Partner): # some company-specific data tax_no = models.CharField() How can I convert a Company instance to a Person one, and vice-versa? Let's say someone mistakenly created a

Multiple Inheritance

末鹿安然 提交于 2020-01-11 08:01:10
问题 #include<iostream> using namespace std; class A { int a; int b; public: void eat() { cout<<"A::eat()"<<endl; } }; class B: public A { public: void eat() { cout<<"B::eat()"<<endl; } }; class C: public A { public: void eat() { cout<<"C::eat()"<<endl; } }; class D: public B, C { }; int foo(A *ptr) { ptr->eat(); } main() { D obj; foo(&(obj.B)); //error. How do i call with D's B part. } The above foo call is a compile time error. I want to call foo with obj's B part without using virtual

Sequence of constructor calls in multiple inheritance

人走茶凉 提交于 2020-01-11 05:11:07
问题 I have tried to find a lot that what if only one class is made virtual in multiple inheritance ? The behaviour of constructor call is not clear to me in this case. Let say for example code- #include<iostream> using namespace std; class grand{ public: grand(){cout<<"grandfather"<<endl;} }; class parent1:virtual public grand{ //virtual used only here public: parent1(){cout<<"parent1 "<<endl;} }; class parent2: public grand{ public: parent2(){cout<<"parent2"<<endl;} }; class child:public parent1

boost shared_from_this and multiple inheritance

≡放荡痞女 提交于 2020-01-09 19:47:48
问题 I am currently having some troubles when using boost enable_shared_from_this and multiple inheritance. The scenario can be described as follows: Class A implements some functionality and should inherit from enable_shared_from_this Class B implements another functionality and should inherit from enable_shared_from_this Class D inherits functionalities from A and B ( class D : public A, public B {} ) When using some class B functionality from class D I got an exception ( bad_weak_ptr ) To

boost shared_from_this and multiple inheritance

心已入冬 提交于 2020-01-09 19:47:35
问题 I am currently having some troubles when using boost enable_shared_from_this and multiple inheritance. The scenario can be described as follows: Class A implements some functionality and should inherit from enable_shared_from_this Class B implements another functionality and should inherit from enable_shared_from_this Class D inherits functionalities from A and B ( class D : public A, public B {} ) When using some class B functionality from class D I got an exception ( bad_weak_ptr ) To

C++ Calling a virtual method from a multiply inherited template class

社会主义新天地 提交于 2020-01-06 19:28:56
问题 I have a lot of code here but I'm afraid this is as little code as I could put to convey the problem, so please bear with me: #include <iostream> #define ASINSTANCE(x, type, y) \ type * y = dynamic_cast<type *>(&(x)); \ if (y) class Fruit { virtual void a() = 0; // This is to surpress the "Fruit isn't polymorphic" we'd otherwise get. }; class Apple : public Fruit { virtual void a() { } }; class Orange : public Fruit { virtual void a() { } }; class Banana : public Fruit { virtual void a() { }

Doubly chained conversions between classes

大城市里の小女人 提交于 2020-01-06 13:58:54
问题 I have a series of classes A, B, C, ... I want to define conversion between any pair of classes. The conversion has to follow the ordering of classes in the series. For example, a conversions from A to C has the following steps: A converts to B. B finally converts to C Similarly, a conversion from C to A has the following steps: C to B B to A I try to modify the answer of my last question: Chained conversion between classes without public inheritances But I can only get chained conversion

Doubly chained conversions between classes

橙三吉。 提交于 2020-01-06 13:58:36
问题 I have a series of classes A, B, C, ... I want to define conversion between any pair of classes. The conversion has to follow the ordering of classes in the series. For example, a conversions from A to C has the following steps: A converts to B. B finally converts to C Similarly, a conversion from C to A has the following steps: C to B B to A I try to modify the answer of my last question: Chained conversion between classes without public inheritances But I can only get chained conversion

template multiple variadic inheritance with variadic argument types

十年热恋 提交于 2020-01-06 04:23:06
问题 I need to inherit multiple times the following class, taking variadic arguments as template parameters. template <class SignalDispatcherClass, class ... ArgTypes> class ISignalMap { //private public: void RegisterSlot(SignalAddress pSignalFunc, ISlotInvoker<ArgTypes...>* pSlotInvoker) { //implementation } }; So far I can expand a parameter pack and get multiple class specializations, but with functions taking only one argument. template <class SignalDispatcherClass, class ... ArgTypes> class

two interfaces, multiple inheritance combine into one container?

荒凉一梦 提交于 2020-01-05 00:01:32
问题 I stumbled upon the following problem: I have two packages A and B working fine for each own. Each has its own interface and his own implementation. Now i made a package C combining a adapter of A with a concrete Implemenation of B. C actually only implements the Interface of A and is only inheritating and using the Interface of B internally for now. Most of the times that was enough to have only access to the Interface A from a Container, but now i need the methods from B accessible too.