multiple-inheritance

Multiple inheritance with the same variable name in the classes

我的梦境 提交于 2019-12-24 07:32:33
问题 I accidentally run into the problem having member variables with the same name in classes used in multiple inheritance. My basic idea was that the member variables are simple "merged", i.e. a multiple declaration happens. The compiler did not tell me even a warning, see the MWE below. I understand that it is a bad idea to have variables with the same name, so I think it is at least ambiguous to refer to them in the way I do; so I expected at least a warning or maybe an error. 1) Why the

Multiple inheritance with the same variable name in the classes

廉价感情. 提交于 2019-12-24 07:32:14
问题 I accidentally run into the problem having member variables with the same name in classes used in multiple inheritance. My basic idea was that the member variables are simple "merged", i.e. a multiple declaration happens. The compiler did not tell me even a warning, see the MWE below. I understand that it is a bad idea to have variables with the same name, so I think it is at least ambiguous to refer to them in the way I do; so I expected at least a warning or maybe an error. 1) Why the

MRO with multiple inheritance in python

穿精又带淫゛_ 提交于 2019-12-24 02:33:15
问题 In the documentation on the Python webpage the method resolution order for classic classes in python is described as a depth-first left-to-right search. I tried to test this with this piece of code: class A(object): def __init__(self): print "Initialized A" class B(A): def test(): print "Initialized B" class C(A): def __init__(self): print "Initialized C" class D(B, C): def __init__(self): super(D, self).__init__() print "Initialized D" When I create an instance of object D: D() I get the

Is it safe to use *virtual* multiple inheritance if QObject is being derived from DIRECTLY?

我们两清 提交于 2019-12-23 21:09:24
问题 I understand that in general, multiple inheritance from QObject -derived classes (even virtual multiple inheritance) is not supported in Qt. I understand the reason to be (I think) that even in the virtual inheritance case, the Qt classes do not themselves virtually inherit from QObject . For example, if you attempt to derive a class virtually from both QWidget and QThread , this is placing the virtual inheritance in an irrelevant place in the inheritance chain and you still wind up with two

Java methods expecting parameters with multiple inheritance

ε祈祈猫儿з 提交于 2019-12-23 19:41:10
问题 I don't know why I can't find an answer to this online. I have classes that implement multiple methods and I would like to write methods to expect them. I don't know how to do it though or if it's even possible. E.g: public void yellAtPet(<? extends Pet implements YellableAt> arg) { arg.yellAt("Don't go there!"); arg.pet("Good Boy"); } 回答1: This should work fine as a generic method, without making your entire class generic: public <T extends Pet & YellableAt> void yellAtPet(T arg) { arg

Best Pattern for Storing Common Settings across Multiple Classes

情到浓时终转凉″ 提交于 2019-12-23 18:25:50
问题 I'm creating two separate classes for accessing a custom file. Let's call my classes MyReader and MyWriter . I'm following the same pattern that .NET classes such as StreamReader and StreamWriter follow, where there is a separate class for reading and writing. In addition to following an established pattern, this also solved some other problems for me. However, I really need a few common settings for both the reader and writer classes. For example, I have a delimiter character that the user

C++/CLI: inherit from one CLR class, multiple C++ classes

偶尔善良 提交于 2019-12-23 16:26:53
问题 In C++/CLI, I want a class hierarchy similar to the following: Foo FooA : Foo, ClrClassA FooB : Foo, ClrClassB Is it possible for FooA to share a (non CLR) base class while also inheriting from separate CLR classes? If not, what would be the best way for FooA and FooB to share common code? 回答1: Generally speaking, composition is often better than inheritance as it tends to lead to less tightly coupled designs. If you're mixing managed and unmanaged code, it's generally easier in my experience

Mechanics of multiple inheritance compared to templates wrt building flexible designs

旧街凉风 提交于 2019-12-23 15:19:02
问题 This is a narrower version of the question put on hold due to being too broad. On pages 6-7 of Modern C++ Design , Andrei Alexandrescu lists three ways in which the multiple inheritance is weaker than templates with respect to building flexible designs. In particular, he states that the mechanics provided by multiple inheritance is poor (the text in square brackets and formatting are mine as per my understanding of the context): In such a setting [i.e. multiple inheritance ], [to build a

How to encapsulate different classes within one class mantaining their unique methods? (multiple inheritance in delphi?)

人走茶凉 提交于 2019-12-23 13:15:27
问题 I'm currently rewriting a free educational digital circuit simulator to add inertiality to its features. My problem is how to dispatch events to original classes adding a pre-elaboration to them. I have something like this: TC1 = class ID: integer; Connections : array [integer] of Pin; function Func1; virtual; function FuncN; end; TC2-1 = class (TC1) function Func1; override; function My1Func(); end; TC2-n = class (TC1) function Func1; override; function MyNFunc(); end; TContainer = class C1

C++ COM design. Composition vs multiple inheritance

佐手、 提交于 2019-12-23 13:03:05
问题 I'm trying to embed a browser control in my application (IWebBrowser2). I need to implement IDispatch, IDocHostShowUI, IDocHostUIHandler etc to make this work. I am doing this in pure C++/Win32 api. I'm not using ATL, MFC or any other framework. I have a main class, called TWebf, that creates a Win32 window to put the browser control in and makes all the OLE calls needed to make it work. It's also used for controlling the browser control, with methods like Refresh(), Back(), Forward() etc.