Initialising global associative array

Paul via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 6 13:50:32 PDT 2015


On Saturday, 6 June 2015 at 20:39:14 UTC, anonymous wrote:
> On Saturday, 6 June 2015 at 20:30:50 UTC, Paul wrote:
>> However, I now get an 'undefined identifier' error when 
>> compiling and trying to access the AA from a function within 
>> the same module.
>>
>> static this()
>> {
>>  string[string] tagWords = [ 	"DIST" : "Distance", .....
>> }
>>
>> ...
>>
>>  if(tag in tagWords)
>>  {
>>    retVal.tag = tagWords[tag]; <---- 'Error: undefined 
>> identifier tagWords'
>>    ...
>
> You have to declare tagWords in module scope, but initialize it 
> in the static constructor:
>
> string[string] tagWords;
> static this()
> {
>     tagWords = [ 	"DIST" : "Distance", .....
> }
>
>>
>> According to Ali's book that looks like a linker message
>
> Nope, that's not a linker message.
>
> "undefined identifier" = compiler
> "undefined reference" = linker

Doh! Thank you anonymous person :D


More information about the Digitalmars-d-learn mailing list