Why defining alias and not auto when using a template?

Bienlein jeti789 at web.de
Fri Apr 4 06:23:46 PDT 2014


Hello,

I took some code snippet from some sample D code and modified it 
a bit:

template TCopy(T, V) {
   private int i = 2;
	
   void copy(out T to, out V to2, T from) {
     to = from;
     to2 = from;
     writeln("i: ", i);
   }
}

void main(string[] args)
{
	int x = 2;
	int y = 2;
	alias myCopy = TCopy!(int, int);	
	myCopy.copy(x, y, 37);
	writeln("x: ", x, " y: ", y);
}

My question is now why I have to declare and alias as in

alias myCopy = TCopy!(int, int);

If I define auto instead of alias, it does not compile. My 
question is why defining auto does not work. I would consider 
this more intuitive.

Thanks, Bienlein


More information about the Digitalmars-d-learn mailing list