Thread overview
Type qualifiers - inout error
Jun 16, 2011
Claudiu Verdes
Jun 17, 2011
bearophile
June 16, 2011
Hi,

I'm new to D and trying to follow Alexandrescu's TDPL code examples I came across an error on the code below:

class A
{
inout(int) val() inout
{
return _val; // error - see below
}
private int _val;
};

The compiler (dmd v2.052) complains on the marked line with the message
"Error: inout on return means inout must be on a parameter as well for inout
inout(int)()".

What am I doing wrong? TDPL has a very similar example...

Regards,
Claudiu

P.S. Is there a netiquette (a la C++ FAQ lite) about posting on this forum
that I should be aware of?


June 17, 2011
Claudiu Verdes:

> What am I doing wrong? TDPL has a very similar example...

I think this TDPL example is not good. And generally inout is not fully implemented in D yet.


> P.S. Is there a netiquette (a la C++ FAQ lite) about posting on this forum
> that I should be aware of?

I think there isn't one. Anything goes! ;-)

Bye,
bearophile
June 17, 2011
On Thu, 16 Jun 2011 22:12:49 -0400, bearophile <bearophileHUGS@lycos.com> wrote:

> Claudiu Verdes:
>
>> What am I doing wrong? TDPL has a very similar example...
>
> I think this TDPL example is not good. And generally inout is not fully implemented in D yet.

Yes, a better example would be:


class A
{
	ref inout(int) val() inout
	{
		return _val;
	}
	private int _val;
}

inout is only relevant if the data type being returned has a reference in it, because a value-only type is implicitly castable to any constancy (const, immutable, or mutable).

As bearophile says, inout is not properly implemented yet.

-Steve