Associative array for array of classes

Derek Parnell derek at psych.ward
Wed Apr 26 22:10:17 PDT 2006


On Wed, 26 Apr 2006 23:49:07 -0500, clayasaurus wrote:

> import std.stdio;
> 
> int main()
> {
> 	char[] i = "3";
> 
> 	int[char[]] assoc;
> 	assoc[i] = 3;
> 
> 	Class[char[]] assoc2;
> 
> 	// doesn't work
> 	if (assoc2[i] is null)
> 		assoc2[i] = new Class;
> 
> 	// works
> 	assoc2[i] = new Class;
> 
> 	writefln("hi");
> 
> 	return 0;
> }
> 
> class Class
> {
>   public:
> 	this(){}
> 	int x,y;
> }

Try this ...

  if (!(i in assoc2))
    assoc2[i] = new Class;

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
27/04/2006 3:09:47 PM



More information about the Digitalmars-d-learn mailing list