Associative Array of structs

Zane zane.sims at gmail.com
Tue Dec 2 16:34:19 PST 2008


I tried writing to an associative array and got the exception:

tango.core.Exception.ArrayBoundsException at test(15): Array index out of bounds

the program below causes the exception:

module test;

import tango.io.Stdout;
import tango.io.Console;
	
struct S {uint i;}
		
int main()
{
	S[char[]] s;
	
	s["test"].i = 1;	

	Stdout.format("Done!").flush;

	return 0;
}

But the program below works fine:

module test;

import tango.io.Stdout;
import tango.io.Console;
	
struct S {uint i;}
		
int main()
{
	S[char[]] s;
	
	S t;
	t.i = 1;
		
	s["test"] = t;

	Stdout.format("Done!").flush;

	return 0;
}

Am I supposed to be able to do both methods, or is the second the only possible way?  Some explanation would be very helpful.

Thanks for your time,
Zane



More information about the Digitalmars-d mailing list