Returning reference to integer from property setter function

m0rph m0rph.mailbox at gmail.com
Tue Oct 16 07:43:08 PDT 2012


Hi! How I can return from function a reference to int? Here is a
simple code, to demonstrate my problem:

struct Foo {
public:
	@property int foo() const
	{
		return x_;
	}
	
	@property ref int foo(int value)
	{
		x_ = value;
		return x_;
	}
	
private:
	int x_;
}


void main()
{
	auto f = Foo;
	f.foo += 5;
}


When I try to build this code, I get the error at line "f.foo +=
5" with message: "Error: f.foo() is not an lvalue". I thought the
ref qualifier causes the compiler to return a reference in that
case.


More information about the Digitalmars-d-learn mailing list