multiple-inheritance

PyQt5: Issues with a Mixin with a metaclass within a derived QWidget class

扶醉桌前 提交于 2019-12-08 03:36:53
问题 I'm having issues trying to add a mixin with a metaclass to a class whose base is a QWidget. I'm aware that PyQt5 supports cooperative multiple inheritance and if my MixIn class has no metaclass then things work fine. However, if it has a metaclass - whether it be the pyqtWrapperType metaclass shared by QWidgets or a derived metaclass, then I receive the following error: Process finished with exit code -1073741819 (0xC0000005) The code for the rest of the script runs, but the QWidget does not

Why is this the same even when object pointers differ in multiple inheritance?

半城伤御伤魂 提交于 2019-12-07 16:31:23
问题 When using multiple inheritance C++ has to maintain several vtables which leads to having "several views" of common base classes. Here's a code snippet: #include "stdafx.h" #include <Windows.h> void dumpPointer( void* pointer ) { __int64 thisPointer = reinterpret_cast<__int64>( pointer ); char buffer[100]; _i64toa( thisPointer, buffer, 10 ); OutputDebugStringA( buffer ); OutputDebugStringA( "\n" ); } class ICommonBase { public: virtual void Common() = 0 {} }; class IDerived1 : public

C++: Memory layout of classes using inheritance

谁说胖子不能爱 提交于 2019-12-07 15:54:03
问题 I know how data will be packed is not specified by the standard. I was just trying to get an idea about the memory layout of classes ( esp. how dynamic_cast<void*> guarantees to return a pointer to the start of the most derived class). I could not think of any explanation about the output of the following code: struct A{ int a;}; struct B{ int b;}; struct C: public A, public B { int c;}; struct D:public C {int d;}; int main(){ D* ob=new D; A* a = ob; B* b = ob; C* c = ob; } Printing the

Why do IUnknown* pointers retrieved through different interfaces of the same COM object have the same value?

与世无争的帅哥 提交于 2019-12-07 13:17:21
问题 I have the following hierarchy of COM interfaces and a class implementing them: interface IX : public IUnknown{}; interface IY : public IUnknown{}; class CA: public IX, public IY{}; Here class CA effectively inherits from IUnknown twice. We know there are two vtable pointers in class CA - one is pointed to IX and another is pointed to IY . So IUnknown stored in the IX subobject is different from IUnknown stored in the IY subobject. Yet when we call IX::QueryInterface() or IY::QueryInterface()

Why the size of empty class that is derived from two empty classes is 2?

﹥>﹥吖頭↗ 提交于 2019-12-07 12:10:32
问题 What I know is that size of empty class is 1 just to conform to the standard that does not allow objects (and classes thereof) of size to be 0. Here, I am getting size of a derived class D as 2. Why behavior is different in this case given that there is no data member or virtual pointer inherited from class B and C to D? #include<iostream> using namespace std; class A {}; class B : public A {}; class C : public A {}; class D : public B, public C {}; int main() { cout<<"Size of D is: "<<sizeof

Choosing which base class to override method of

[亡魂溺海] 提交于 2019-12-07 08:41:02
问题 Given the following: class Observer { public: virtual void Observe(Parameter p) = 0; }; template<size_t Tag> class TaggedObserver : public Observer { }; class Thing : public TaggedObserver<0>, TaggedObserver<1> { public: virtual void Observe(Parameter p) override; }; Thing::Observe overrides both TaggedObserver<0>::Observe and TaggedObserver<1>::Observe . Is there a way to provide a different override for each base class? Rationale: I want the class to be able to observe two notification

What is the proper approach to swap and copy idiom in virtual inheritance?

妖精的绣舞 提交于 2019-12-07 07:32:41
问题 Consider classic virtual inheritance diamond hierarchy. I wonder to know what is the right implementation of copy and swap idiom in such hierarchy. The example is a little artificial - and it is not very smart - as it would play good with default copy semantic for A,B,D classes. But just to illustrate the problem - please forget about the example weaknesses and provide the solution. So I have class D derived from 2 base classes (B<1>,B<2>) - each of B classes inherits virtually from A class.

Implement two functions with the same name but different, non-covariant return types due to multiple abstract base classes

六眼飞鱼酱① 提交于 2019-12-07 03:16:34
问题 If I have two abstract classes defining a pure virtual function with the same name, but different, non-covariant return types, how can I derive from these and define an implementation for both their functions? #include <iostream> class ITestA { public: virtual ~ITestA() {}; virtual float test() =0; }; class ITestB { public: virtual ~ITestB() {}; virtual bool test() =0; }; class C : public ITestA, public ITestB { public: /* Somehow implement ITestA::test and ITestB::test */ }; int main() {

Is it better to use `#ifdef` or inheritance for cross-compiling?

≯℡__Kan透↙ 提交于 2019-12-07 02:38:45
问题 To follow from my previous question about virtual and multiple inheritance (in a cross platform scenario) - after reading some answers, it has occurred to me that I could simplify my model by keeping the server and client classes, and replacing the platform specific classes with #ifdefs (which is what I was going to do originally). Will using this code be simpler? It'd mean there'd be less files at least! The downside is that it creates a somewhat "ugly" and slightly harder to read Foobar

python multi inheritance with parent classes have different __init__()

。_饼干妹妹 提交于 2019-12-07 02:12:27
Here both B and C are derived from A , but with different __init__() parameters. My question is how to write the correct/elegant code here to initialize self.a,self.b,self.c1,self.c2 in the following example? Maybe another question is--is it a good coding practice to do this variable setting in __init()__ function or it is better to use simpler __init__() function, and do set() function for each class later, which seems not as simple as to just do it in __init()__ ? class A(object): __init__(self,a): self.a=a class B(A): __init__(self,a,b): super(B,self).__init__(a) self.b=b class C(A): __init