const functions in D 2.0

Steven Schveighoffer schveiguy at yahoo.com
Mon Nov 5 17:40:20 PST 2007


"Jarrett Billingsley" wrote
> "Steven Schveighoffer" <schveiguy at yahoo.com> wrote in message 
> news:fgoak7$24ao$1 at digitalmars.com...
>> How does one declare const/invariant member functions in D 2.0 that don't 
>> return void?  If it's just prefixing, how does one declare 
>> const/invariant functions that return const/invariant references?
>>
>> The web site isn't very helpful on this matter.
>>
>> -Steve
>>
>
> const Bar foo()
> {
>    // returns a non-const Bar, but can't modify this.
> }
>
> const const(Bar) foo()
> {
>    // returns a const(Bar).
> }
>
> At least I'm pretty sure.
>

Experimentation proves you are correct.  Thanks!

This really should be more prominent on the web site.

-Steve 




More information about the Digitalmars-d-learn mailing list