digitalmars.D.learn - multidim array with enum
- Chris Katko (26/26) Jun 18 2022 I'm having difficulty figuring out exactly what signature D is
- Adam D Ruppe (12/15) Jun 18 2022 I'm actually not sure if that [DIR] is an associative array or
I'm having difficulty figuring out exactly what signature D is
expecting.
````D
enum DIR
{
UP = 0,
DOWN,
LEFT,
RIGHT,
UPLEFT,
UPRIGHT,
DOWNRIGHT,
DOWNLEFT,
}
BITMAP*[2][DIR] bmps;
// ...
bmps[DIR.UP][0] = nope.
bmps[DIR.UP][0] = new BITMAP *; // nope
bmps[DIR.UP][0] = new BITMAP; // nope
bmps[DIR.UP] = new BITMAP*[2]; // compiles. runtime range
violation.
````
I swear this all worked fine when it was just:
````D
bmps[DIR] bmps;
````
Jun 18 2022
On Saturday, 18 June 2022 at 17:19:24 UTC, Chris Katko wrote:I'm having difficulty figuring out exactly what signature D is expecting. BITMAP*[2][DIR] bmps;I'm actually not sure if that [DIR] is an associative array or DIR's base type or a static array of DIR's size. I *think* it is an assoc array... let's test it using the `in` operator: auto a = DIR.UP in bmps; That compiled. So this must be an associative array! Try this instead: BITMAP*[2][DIR.max] bmps; That's a static array of directions and I think that's what you intended and the other things should work as you want too with this.
Jun 18 2022








Adam D Ruppe <destructionator gmail.com>