What can you "new"

BCS none at anon.com
Sun Mar 22 12:43:25 PDT 2009


Hello Denis,

> Hmm.. Not a common case, but looks like a bug. Or a clever design
> decision :P
> 
> Certainly, you can create an int using new:
> 
> int* i = new int;
> 
> Why can't you create 'char[]'?
> 
> T create(T) {
> return new T;
> }
> int* i = create!(int); // fine
> char[]* c = create!(char[]); // error

that should be:
> T* create(T)() {
> return new T;
> }

but works (or not) as you said

OTOH this works:

T* create(T)() {
T[] ret = new T[1];
return &ret[0];
}

void main()
{
int* i = create!(int); // fine
char[]* c = create!(char[]); // error
}





More information about the Digitalmars-d mailing list