Re: Accessing array elements with a pointer-to-array

2024-01-26 Thread Stephen Tashiro via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ]; static_array[2][1] = 6; } The static array has length 2, so index 2 is out

Accessing array elements with a pointer-to-array

2024-01-25 Thread Stephen Tashiro via Digitalmars-d-learn
Can the elements of an array be accessed with a pointer using the usual indexing notation (e.g."[2][0]") for array elements? - or must we treat the elements associated with the pointer as 1-dimensional list and use pointer arithmetic? A more elementary question is why array index 2 is out-of-b

Re: Constructing arrays of structs

2024-01-23 Thread Stephen Tashiro via Digitalmars-d-learn
On Tuesday, 23 January 2024 at 18:23:22 UTC, Renato wrote: This works , your mistake was to not actually assign the array to the class' field! Change this line: ```d auto array = new Point[][](the_dimension,the_dimension); ``` To this: ```d this.array = new Point[][](the_dimension,the_dimens

Constructing arrays of structs

2024-01-23 Thread Stephen Tashiro via Digitalmars-d-learn
If the constructor of a class needs to create an array of structs whose dimensions are inputs, what's the syntax for doing this? For a non-example, the following program errors in main() because in t.array[][] "index [0] is out of bounds". import std.stdio; struct Point { uint