Array/collection of templated class

Hasan Aljudy hasan.aljudy at gmail.com
Thu Apr 20 01:22:35 PDT 2006


Chris Nicholson-Sauls wrote:
> I'm working on a project of mine, and I came across this little 
> problem.  Now, it may well be that the solution is staring me in the 
> face, but I just can't seem to come up with a feasible solution to this: 
> I can't have an array of a templated class.
> 
> To illustrate:
> 
> ########## foo.d
> # class Foo (T) {
> #   public this (T a_value) { p_value = a_value; }
> #
> #   public T value () { return p_value; }
> #   private T p_value;
> # }
> #
> # void main () {
> #   Foo[] arr;
> # }
> 
> This will give the error:
> foo.d(9): class foo.Foo(T) is used as a type
> 
> Now, granted, I expected this.  But I'm at a loss as to what to do.  
> Sure, if I had a way of knowing the signatures of the template instances 
> I could just use "Object[]" decleration and a cast() expression on the 
> lookup, but this is for a system where I usually won't know.
> 
> Ideas?
> 
> -- Chris Nicholson-Sauls

Hmm .. templates are generally used for things that you know at compile 
time, if you don't, well .. trying doing something different.



More information about the Digitalmars-d mailing list