What can you "new"
Unknown W. Brackets
unknown at simplemachines.org
Sun Mar 22 15:43:58 PDT 2009
The new construct allocates memory. You can "new" anything that
requires a set amount of memory.
This is equivalent to what you want:
auto s = new char[0];
Which creates a new dynamic array with no length (yet.) You can resize
it later. Remember, that is not the same as saying:
char[0] s;
Which creates a static array. This cannot be resized.
For the sake of people used to other languages (where arrays are
objects), it is possible "new type_t[]" could be considered the same as
"new type_t[0]", but that is an RFE not a bug.
-[Unknown]
Steve Teale 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?
>
More information about the Digitalmars-d
mailing list