Pointer to array allocation
0ffh
spam at frankhirsch.net
Sun Jun 17 14:51:25 PDT 2007
Hi!
Probably most here know that something like:
alias Var[] Lst;
void test()
{
Lst *l=new Lst;
foo(l);
}
will result in "Error: new can only create structs,
dynamic arrays or class objects, not Var []'s".
So what is the D way of doing what I mean?
I came up with:
Lst* newLst()
{
void[] v;
v.length=Lst.sizeof;
return cast(Lst*)v.ptr;
}
but this looks like an ugly hack to me, actually
I'm not even sure yet it won't run into trouble...
Regards, Frank
p.s.
/I really do mean a pointer to a dynamic array./
More information about the Digitalmars-d-learn
mailing list