Templated Interfaces?
Ary Borenszweig
ary at esperanto.org.ar
Mon Aug 25 19:16:52 PDT 2008
Sergey Gromov a écrit :
> Ary Borenszweig <ary at esperanto.org.ar> wrote:
>> If you put an integer into the array declaration, it *is* declared as a
>> static array.
>>
>> Static array:
>> -------------
>> auto array = new I!(char)[3];
>> - array is of type I!(char)[3] (static array)
>> - you cannot append using ~
>> - you can assign or access using indices
>> - you can initialize it like that or using an array literal
>
> import std.stdio;
> void main() {
> auto a = new int[3];
> writeln(typeof(a).stringof);
> }
>
> prints "int[]". new expression *always* produces a dynamic array.
Ouch. I first wrote
I!(char)[3] array = new I!(char)[3];
which compiles, and makes array a static array (you can't append to it).
Then, for simplicity, I changed the type to auto... it seems new makes a
dynamic array, but then it is implicitly converted to a static one, right?
More information about the Digitalmars-d-learn
mailing list