Question about template mixins as nested functions.

Gerald Stocker gobstocker at
Thu Feb 15 21:31:07 PST 2007


I have a question about using a template mixin to add a nested function 
to a class method, when the nested function references class member 
variables. For example:

class SomeClass
     int memberVar;
     void doSomething()
         int localVar;
         mixin HelperFunction;	// see below

template HelperFunction()
     void helperFunction()
         localVar++;	// This works fine
         memberVar++;	// Error: need 'this' to access member memberVar

I'm not sure why the mixed-in nested function can't access member 
variables of the enclosing class (it works if I just write the nested 
function directly inside the class method). Is this a bug, or (more 
likely) have I not fully grasped the ins and outs of using template mixins?

Gerald Stocker

More information about the Digitalmars-d-learn mailing list