getters and setters not an lvalue

Jacob Carlborg doob at me.com
Wed Oct 31 08:14:48 PDT 2012


On 2012-10-31 13:46, maarten van damme wrote:
> In my current code I'd like to do something ala:
>
> void main(){
> 		getsettest test=new getsettest();
> 		
> 		test.value+=1;
> }
>
> class getsettest{
> 	int myvalue;
> 	
> 	this(){
> 	}
> 	
> 	@property{
> 	
> 		int value(){
> 			return myvalue;
> 		}
> 		
> 		void value(int value){
> 			myvalue=value;
> 		}
> 	}
> }
>
> but this gives the following error:
> test.d(4): Error: test.value() is not an lvalue
>
> Is there a rationale behind this decision of not translating
> test.value+=1 to test.value= test.value +1 ?

I think we need implement property rewrite to properly handle this.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list