On 5/18/15 7:55 PM, Freddy wrote:
How do you allocate an associative array on the heap?
----
void main(){
     alias A=int[string];
     auto b=new A;
}
----
$ rdmd test
test.d(4): Error: new can only create structs, dynamic arrays or class
objects, not int[string]'s
Failed: ["dmd", "-v", "-o-", "test.d", "-I."]

As others have said, I don't know why you would want to do this, since AA is already simply a wrapper for a pointer to a heap-allocated AA.

But if you wanted to, you could put it in a struct:

struct AA
{
   int[string] x;
}

void main()
{
   auto b = &((new AA).x);
}

-Steve

Reply via email to