April 27, 2004
I think the best way to illustrate this is with code:

class Foo
{
  this() {
    bar_ = new Bar;
  }

  Bar bar() {
    return bar_;
  }

private:
  Bar bar_;
}

class Bar
{
  int opIndex(int key) { return 0; /* Do something here */ }
  int opIndex(int key, int value) { return 0; /* Do something here */ }
}

Assuming Foo f = new Foo;
Using the first operator overload like so:

int i = f.bar[0];

This works fine. While using the second does not:

f.bar[0] = 100;

And the compiler generates: " 'f.bar().opIndex(20)' is not an lvalue "
Calling the property explicitly works though:

f.bar()[0] = 100;