Mixin Problems with D2.0

Simen Kjaeraas simen.kjaras at gmail.com
Thu Mar 6 04:12:26 PST 2008


On Thu, 06 Mar 2008 12:02:24 +0100, Brian White <bcwhite at pobox.com> wrote:

> I'm new to D and am playing with D2.0.  When I try to compile the  
> example on http://www.digitalmars.com/d/2.0/mixin.html, I get a compiler  
> error:
>
> --------------------------------------------------------------
> template GenStruct(char[] Name, char[] M1)
> {
>      const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
> }
>
> mixin(GenStruct!("Foo", "bar"));
> --------------------------------------------------------------
> testmixin.d(6): template instance GenStruct!("Foo","bar") does not match  
> any template declaration
> attribute argument to mixin must be a string, not  
> (GetStruct!("Foo","bar"))
> --------------------------------------------------------------
>
> Is there something else needed?
>
> -- Brian


The problem is that "Foo" and "bar", as D strings, are invariant(char)[],  
not char[].

The solution is to change the template to

> template GenStruct(const char[] Name, const char[] M1)

-- Simen


More information about the Digitalmars-d-learn mailing list