Some help on Mixin Template at Class level.

Simen Kjaeraas simen.kjaras at gmail.com
Sun May 22 11:17:16 PDT 2011


On Sat, 21 May 2011 11:40:22 +0200, Matthew Ong <ongbp at yahoo.com> wrote:

> Using your code I have this error:
>
> src\Sample.d(16): Error: undefined identifier btype, did you mean  
> template AType(string name,U,alias V)?
> src\Sample.d(16): Error: mixin AType!("ClassB",string,_error_) does not  
> match template declaration AType(string name,U,alias V)
>
> Could you please ensure it is compilable code and so that I can test the  
> template shown by you.

Sorry about that.


string ATypeGenerator( string name ) {
     return "class " ~ name ~ " : ClassC {
private:
     U value;
public:
     this(){}
     void print(){}
     mixin V;
}";
}

mixin template AType( string name, U, alias V ) {
     mixin( ATypeGenerator( name ) );
}

class ClassC {}

mixin template btype() {
     void someFunction() {}; // Content of a class.
}

mixin AType!("ClassB", string, btype);

void main() {
     ClassC r = new ClassB();
}

-- 
   Simen


More information about the Digitalmars-d-learn mailing list