Template mixin problem

Bill Baxter wbaxter at gmail.com
Mon Dec 15 01:07:08 PST 2008


On Mon, Dec 15, 2008 at 5:58 PM, Olli Aalto <oaalto at gmail.com> wrote:
> Bill Baxter wrote:
>>
>> On Mon, Dec 15, 2008 at 5:48 PM, Olli Aalto <oaalto at gmail.com> wrote:
>>>
>>> Ok, downs figured it out on #D. You can't have mixins in templates, which
>>> is
>>> a big disappointment.
>>>
>>> Removing the HelloData mixin from HelloSpeaker and all references to
>>> helloStr it "works".
>>
>> Hmm, didn't know that.  But also if you import a module that uses a
>> mixin, the module that uses the mixin also needs to import the mixin
>> module.  I'm sure that didn't make any sense.
>>
>> I.e. you may need to import mixins.HelloData in mixins.HelloWorld.
>> And maybe import all the mixin modules in in main.
>>
>
> Yeah, just tried that and it worked. :) I think all this makes some kind of
> sense, but having to import the module for HelloData in HelloWorld shouldn't
> be needed. It's already been mixed-in in HelloSpeaker so from the
> HelloWorld's standpoint there is no HelloData. But any way glad to have it
> working.

But modules are inherited privately by default.
If you use "public import blahblah" for the modules the mixins require
then you can get around the problem.

Also there is a trick that I think h3r3tic first noticed -- you can
actually put an import statement inside the template, and at least if
it gets mixed into a class, it will work.  May work in other cases
too, but not so sure about that.

--bb


More information about the Digitalmars-d-learn mailing list