Why defining alias and not auto when using a template?

anonymous anonymous at example.com
Fri Apr 4 06:51:50 PDT 2014


On Friday, 4 April 2014 at 13:23:48 UTC, Bienlein wrote:
> template TCopy(T, V) {
[...]
> }

On Friday, 4 April 2014 at 13:35:58 UTC, Bienlein wrote:
> auto myCopy = new TCopy!(int, int);	
> alias myCopy = new TCopy!(int, int);	
>
> Neither nor compiles now. How can? Seems to me a template is 
> not a class in that sense ?!

Templates are not classes, yes. You can make a class template:

class TCopy(T, V) {...}

The template instance TCopy!(int, int) then is a class type which
can be newed, etc.

The same works with structs, functions, interfaces. Add some
(template) parameters and it becomes a template that instantiates
to the corresponding entity.


More information about the Digitalmars-d-learn mailing list