On 5/3/2009 3:44 AM, flourish wrote:
Hi,

why does the following code not compile -- or how to declare a (usable)
property of an associative array field?

//////////////////////
class Test
{
   private int[int] _testMap;
   public int[int] testMap() {return _testMap;}
}


testMap() is a getter and can only return the value it is designed to.
You must implement a setter to accomplish what you are trying to di. Unfortunately I'm not sure how you do that with AAs so I'll leave that to someone that's a little smarter than I.

I think that maybe implementing opIndexAssign might work for you though:

public void opIndexAssign(int val, int ndx){ _testMap[ndx] = val; }

Then you can simply "test[0] = 1;" to get the desired effect.

void main()
{
   Test test = new Test();
   test.testMap[0] = 1;
}
/////////////////

*** Error: test.testMap() is not an lvalue


Regards,
     flourish




Reply via email to