Mixin template, "no identifier for declarator"
    SimonN via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue Oct 27 00:56:49 PDT 2015
    
    
  
Hi,
I'd like to generate several very similar class methods with a 
mixin template.
The mixin template shall take alias parameters, so that different 
methods can
bind it to different fields. Reduced problem case:
     class A {
         int myField;
         mixin template fieldSetter(alias whatField)
         {
             whatField = newVal;
         }
         int setMyField(in int newVal)
         {
             mixin fieldSetter!myField;
         }
     }
Compiler error message, DMD64 v2.068.2, line 6 is "whatField = 
newVal;":
     (6): Error: no identifier for declarator whatField
     (6): Error: declaration expected, not '='
I believe I'm following as closely as appropriate what's 
described at
http://dlang.org/template-mixin.html under "Mixins can 
parameterize symbols
using alias parameters".
Why does it error out on whatField, apparently deeming it to be a 
type?
Can I get this done with mixin templates? (I'd like to avoid 
string mixins,
the workaround with them got a little ugly.)
-- Simon
    
    
More information about the Digitalmars-d-learn
mailing list