getters and setters not an lvalue

Maxim Fomin maxim at maxim-fomin.ru
Wed Oct 31 09:10:35 PDT 2012


On Wednesday, 31 October 2012 at 12:46:12 UTC, 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
>

You can make int value() to return by reference.


More information about the Digitalmars-d-learn mailing list