Mixin helper help

John Chapman john.chapman at live.com
Thu Jan 12 08:03:34 UTC 2023


I'm obviously doing something wrong, but don't quite understand.

```d
mixin template helper() {
   mixin("writeln(12);");
}

struct Foo {
   void opDispatch(string name)() {
     import std.stdio;
     mixin helper!();
     //mixin("writeln(12);");
   }
}

void main() {
   Foo.init.opDispatch!"bar"();
}
```

The compiler emits these errors about the mixin ("writeln(12);"):
unexpected `(` in declarator
basic type expected, not `12`
found `12` when expecting `)`
no identifier for declarator `writeln(_error_)`
semicolon expected following function declaration
declaration expected, not `)`

Why does the commented code work but the mixin not? Thanks for 
any pointers.


More information about the Digitalmars-d-learn mailing list