| June 30, 2004opIndexAssign does not give a real lvalue, is this a bug? | ||||
|---|---|---|---|---|
| 
 | ||||
| If I pass an array element into a function expecting an inout parameter, this compiles fine fine:
void foo() {
	Object[] o;
	bar(o[0]);
}
void bar(inout Object x) {}
But if I do the same thing with a class with index overloads, I get the error "test.d(5): this.opIndex(0) is not an lvalue":
class Test {
	Object opIndex(int i) { return null; }
	Object opIndexAssign(Object o,int i) { return o; }
	void foo() {
		bar(this[0]);
	}
}
void bar(inout Object x) {}
I think I should be able to do this. It makes it trivial to overload foreach if you have indexers, and things like that.
Sam
 | ||||
Copyright © 1999-2021 by the D Language Foundation
  Permalink
Permalink Reply
Reply