From: Paul Brannan Date: 2003-03-11T06:11:27+09:00 Subject: Re: Limited Support for Multiple Inheritance in SWIG/Ruby Mixins are probably the right way to go. As you've noticed, you can't include a Class, so the solution is to have every Class include a Module that has the implementation. This gives you the option of using inheritance to simulate C++ single inheritance and mixins to simulate C++ multiple inheritance. The biggest disadvantage is that you lose the "is-a?" relationship between classes, but you do retain duck typing. There are some issues you should be aware of, though. For one, diamond-inheritance doesn't necessarily work the way you might expect: class Base module Impl def foo puts "Base#foo" end end include Impl end class Left module Impl include Base::Impl def foo puts "Left#foo" end end include Impl end class Right module Impl include Base::Impl def foo puts "Right#foo" end end include Impl end class Derived module Impl include Left::Impl include Right::Impl # no foo() here end include Impl end d = Derived.new d.foo() #=> Right#foo In C++, a program like this is ambiguous (do you call Left::foo() or Right::foo()?). In Ruby, you can never have true diamond inheritance (it's all linear, and Left#foo is inaccessible from Derived). Swig should probably produce a compile-time error if there is ever a function it needs to wrap that would result in an ambiguous call. Another issue is with non-virtual inheritance. Virtual inheritance is easy, because there is only one instance of each base class. Without thinking about the problem some more, I don't know where I would begin wrapping a class that non-virtually inherits multiple times from a single base class. It probably isn't something you should run into often, so it's not a big loss if swig produces an error here, too. Paul