File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -1011,17 +1011,24 @@ $(H3 $(LNAME2 default-initialization, Default Initialization))
1011
1011
)
1012
1012
1013
1013
$(H3 $(LNAME2 length-initialization, Length Initialization))
1014
+
1014
1015
$(P The $(D new) expression can be used to allocate a dynamic array
1015
1016
with a specified length by specifying its type and then using the
1016
1017
`(size)` syntax:
1017
1018
)
1018
1019
1019
- $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1020
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
1020
1021
---------
1021
- int[] i = new int[](5); //i.length == 5
1022
- int[][] j = new int[][](10, 5); //j.length == 10, j[0].length == 5
1022
+ int[] i = new int[](5);
1023
+ i = new int[5]; // same allocation, alternate syntax
1024
+ assert(i.length == 5);
1025
+
1026
+ int[][] j = new int[][](10, 5);
1027
+ assert(j.length == 10);
1028
+ assert(j[0].length == 5);
1023
1029
---------
1024
1030
)
1031
+ $(P See $(GLINK2 expression, NewExpression) for details.)
1025
1032
1026
1033
$(H3 $(LNAME2 void-initialization, Void Initialization))
1027
1034
Original file line number Diff line number Diff line change @@ -2858,11 +2858,20 @@ $(GNAME NewExpression):
2858
2858
)
2859
2859
2860
2860
$(P `new T` constructs an instance of type `T` and default-initializes it.
2861
- The result is:)
2862
- * `T` when `T` is a reference type (e.g. class, dynamic array ,
2863
- $(DDSUBLINK spec/hash-map, construction_and_ref_semantic, associative array ))
2861
+ The result's type is:)
2862
+ * `T` when `T` is a reference type (e.g. classes ,
2863
+ $(DDSUBLINK spec/hash-map, construction_and_ref_semantic, associative arrays ))
2864
2864
* `T*` when `T` is a value type (e.g. basic types, structs)
2865
2865
2866
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
2867
+ ---
2868
+ int* i = new int;
2869
+ assert(*i == 0); // int.init
2870
+
2871
+ Object o = new Object;
2872
+ //int[] a = new int[]; // error, need length argument
2873
+ ---
2874
+ )
2866
2875
$(P The $(INLINE_GRAMMAR *Type(NamedArgumentList)*) form allows passing either a single initializer
2867
2876
of the same type, or multiple arguments for more complex types:)
2868
2877
@@ -2873,13 +2882,11 @@ $(GNAME NewExpression):
2873
2882
2874
2883
$(SPEC_RUNNABLE_EXAMPLE_RUN
2875
2884
---
2876
- int* i = new int;
2877
- assert(*i == 0); // int.init
2878
- i = new int(5);
2885
+ int* i = new int(5);
2879
2886
assert(*i == 5);
2880
2887
2881
- Object o = new Object;
2882
2888
Exception e = new Exception("info");
2889
+ assert(e.msg == "info");
2883
2890
2884
2891
int[] a = new int[](2);
2885
2892
assert(a.length == 2);
You can’t perform that action at this time.
0 commit comments