Class allocation from tuple

Jarrett Billingsley jarrett.billingsley at gmail.com
Thu May 21 07:49:34 PDT 2009


On Thu, May 21, 2009 at 10:31 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> I have a tuple of classes (D1 language), I'd like to instantiate one of them directly with new, but it seems I can't:
>
> template Tuple(T...) { alias T Tuple; }
>
> class Foo { static void foo(){} }
> class Bar {}
> alias Tuple!(Foo, Bar) ClassTuple;
>
> void main() {
>    alias ClassTuple[0] Foo0;
>    new Foo0; // OK
>
>    ClassTuple[0].foo(); // OK
>
>    new ClassTuple[0]; // Not OK
>    new (ClassTuple[0]); // Not OK
> }
>
> Can you tell me what the problem is?
>
> Thank you and bye,
> bearophile

I think it's just a shortcoming in the parser.  When it tries to parse
the type following 'new', it interprets the brackets as meaning an
array type, like when you do "new int[10]" or so.  That's why you get
the error message "can't have array of (Foo, Bar)".


More information about the Digitalmars-d-learn mailing list