www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Type qualifiers - inout error

reply Claudiu Verdes <claudiu.verdes gmail.com> writes:
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?
Jun 16 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
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
Jun 16 2011
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
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
Jun 17 2011