What can you "new"

Denis Koroskin 2korden at gmail.com
Sun Mar 22 11:51:22 PDT 2009


On Sun, 22 Mar 2009 21:31:07 +0300, Steve Teale <steve.teale at britseyeview.com> wrote:

> void str()
> {
>    auto s = new char[];
> }
>
> void main()
> {
>    str();
> }
>
> produces:
>
> str.d(3): Error: new can only create structs, dynamic arrays or class  
> objects, not char[]'s.
>
> What am I missing here, isn't char[] a dynamic array?
>

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




More information about the Digitalmars-d mailing list