Is there a way to get this associative array initialization to work?

Steven Schveighoffer schveiguy at yahoo.com
Tue Jan 9 23:19:04 UTC 2018


On 1/9/18 6:05 PM, WhatMeWorry wrote:
> enum SoundType { MUSIC = 0, SOUND_EFFECT };
> 
> struct Sound
> {
>      string     file;
>      SoundType  musicOrSfx;
>      void*      ptr;   // Mix_Chunk* for sfx;  Mix_Music* for music;
> }
> 
> immutable Sound[string] soundLibrary  =   // line 148
> [
>      "SCRATCH"          : { file : "scratch.wav", musicOrSfx : 
> SOUND_EFFECT, ptr : null },
>      "BACKGROUND_TRACK" : { file : "beat.wav",    musicOrSfx : 
> MUSIC,        ptr : null },
>      "HIGH"             : { file : "high.wav",    musicOrSfx : 
> SOUND_EFFECT, ptr : null }
> ];
> 
> 
> I keep getting a
> source\app.d(148,1): Error: not an associative array initializer
> 
> 

https://issues.dlang.org/buglist.cgi?list_id=218715&longdesc=not%20an%20associative%20array%20initializer&longdesc_type=allwordssubstr&query_format=advanced&resolution=---

Note, I think you need at least Sound.SOUND_EFFECT, etc.

This bug looks particularly relevant: 
https://issues.dlang.org/show_bug.cgi?id=11221

I think it should really work.

-Steve


More information about the Digitalmars-d-learn mailing list