From: Johan Nilsson Date: 2004-12-09T22:12:29+09:00 Subject: Re: Inheritance, mixins and initializers "Robert Klemme" wrote in message news:31qukrF3d6rb9U1@individual.net... > > "Johan Nilsson" schrieb im Newsbeitrag > news:1102594375.344eddcc1c357ac539046c764cd8c6b8@teranews... > > Hi, > > > > I've got a question regarding inheritance, mixins, order of > initialization > > and calling module/super class "initializers". I'd like to do something > > along the lines of (pseudo-ruby code): > > [snip] > > I don't know which real problem you are trying to solve. I can think of > several other approaches. You might want to store your mixin created > instances directly in instance variables and record only the names of > these. Thanks for your reply(s), I'll check them out. I'm actually mapping a legacy C++ construct to Ruby (no, this is not the actual code and probably contain some typos): --- struct FooBarBase {}; struct Foo : FooBarBase {}; struct Bar : FooBarBase {}; class Base { protected: Base(int stuffs) : m_stuff(stuffs, boost::shared_ptr()) {} void add_stuff_at(int index, boost::shared_ptr pfb) { m_stuff.at(index) = pfb; } public: ... functions operating on all "stuff" as a homogenous collection ... private: std::vector > m_stuff; }; template struct FooMixin { FooMixin() : m_pFoo(boost::shared_ptr(new Foo)) { return static_cast(this)->add_stuff_at(which, m_pFoo); } const Foo& foo() const { return *m_pFoo; } private: boost::shared_ptr m_pFoo; }; template struct BarMixin { ... }; struct Derived : Base , FooMixin , BarMixin { Derived() : Base(2) {} }; int main(int, char*[]) { Derived d; const Foo& foo = d.foo(); d.bar(); return 0; } --- To further complicate matters I was trying to use SWIG to inherit from the C++ class "Base" using the cross-language polymorhism feature. Now I believe I'll rewrite this part in Ruby instead (but the FooBaseBase stuff etc will still be wrapped from C++). Thanks again // Johan