On Wed, 5 Jul 2023 at 10:31, Greg Ewing via Python-list <python-list@python.org> wrote: > > On 5/07/23 10:33 am, Alan Gauld wrote: > > (*) C++ is the odd one out because it doesn't have GC, but then > > neither does it have an Object superclass so very often MI in C++ > > does not involve creating diamonds! And especially if the MI > > style is mixin based. > > Even if all your mixins have empty constructors, in C++ there > is still a diamond problem if they have any data members, because > you end up with multiple copies of them. > > But C++ has the concept of virtual base classes, which avoids the > diamond problem, albeit at the expense of making you explicitly > call all the base class constructors in your ancestry.
Yeah, non-virtual MI in C++ is basically composition with a shorthand for calling non-conflicting methods or accessing non-conflicting data members. Point of random interest: Pike actually allows that sort of "composition MI" but will give you back an array of all parents when you seek a superclass's method, giving a very elegant syntax for MI. inherit Thing1; inherit Thing2; void method() { ::method(); //this is actually calling an array of two methods } Python's way of doing it requires that every class choose to cooperate in the MI and then be aware that they are all operating on the same object. Pike's and C++'s can sometimes be used as composition in disguise, but in general, MI does require proper cooperation. ChrisA -- https://mail.python.org/mailman/listinfo/python-list