class template as a type

Karl asdf at asdf.com
Wed Sep 19 20:15:24 PDT 2007


Frits van Bommel Wrote:

> Karl wrote:
> > BCS Wrote:
> > 
> >> void Foo(Test!(somthingToAlias) { }
> >> static Test!(somthingToAlias)[] myarray;
> >>
> >> look for "Explicit Template Instantiation" in
> >>
> >> http://www.digitalmars.com/d/template.html
> > 
> > "somthingToAlias" could be anything right? Lets suppose foo.bar1 or foo.bar2. Then "static Test!(foo.bar1)[] myarray;" would create an array only for elements instantiated from foo.bar1 and i couldn't append an element instantiated from foo.bar2, am i wrong?
> > 
> > 1) Then how could i create an array for generic instantiated elements?
> 
> You could give your template class a non-templated base function, and 
> use that as the type of the array elements.
> 
> > 2) "void Foo(Test!(somthingToAlias) { }", i think something is missing:
> > 
> > - ")".
> 
> Yes, he seems to have made a typo there
> 
> > - A variable name, (correct me if wrong): void Foo(Test!(somthingToAlias)  sta){ }
> 
> Technically the name is optional, but it does come in quite handy when 
> you actually want to *use* the parameter in the function body :).

Thanks for your reply.

"You could give your template class a non-templated base function, and 
use that as the type of the array elements."

I didn't understood. A small example please.

Thanks man.


More information about the Digitalmars-d-learn mailing list