class template as a type
Karl
asdf at asdf.com
Tue Sep 18 23:32:47 PDT 2007
BCS Wrote:
> Reply to Karl,
>
> > Hi,
> >
> > I've been playing around with templates, i'm a newbie in this matter,
> > i created a class template and i want to use it as a type in functions
> > and create arrays of it. Any help please.
> >
> > Code sample:
> >
> > module hello;
> >
> > template Test(alias T)
> > {
> > class Test
> > {
> > this(){} int x; ...
> > }
> > }
> > void Foo(Test t){}
> >
> > static Test[] myarray;
> >
>
> void Foo(Test!(somthingToAlias) { }
> static Test!(somthingToAlias)[] myarray;
>
> look for "Explicit Template Instantiation" in
>
> http://www.digitalmars.com/d/template.html
>
>
Thanks for your reply.
"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?
2) "void Foo(Test!(somthingToAlias) { }", i think something is missing:
- ")".
- A variable name, (correct me if wrong): void Foo(Test!(somthingToAlias) sta){ }
Thanks in advance.
More information about the Digitalmars-d-learn
mailing list