Return by 'ref' problems...
Peter Alexander
peter.alexander.au at gmail.com
Fri May 4 14:26:37 PDT 2012
On Friday, 4 May 2012 at 08:46:38 UTC, Jonathan M Davis wrote:
> On Friday, May 04, 2012 11:38:32 Manu wrote:
>> I try rearranging the syntax to make the first issue stop
>> complaining:
>>
>> ref const(Thing) func2() { return gThing; } // this seems to
>> work now, but
>> i don't like the inconsistency...
>
> That's thanks to the nonsense that putting const on the
> left-hand side of a
> member function is legal, making it so that you _must_ use
> parens with const
> and return types for the const to apply to the return type
> rather than the
> function.
It's not only legal, sometimes it's required, e.g. if you want
type inference on a const member function.
class Foo
{
auto fun() { ... } //ok
auto fun() const { ... } // error, two storage classes
fun() const { ... } // error, expected storage class before
'foo'
const fun() { ... } // correct!
}
More information about the Digitalmars-d
mailing list