const/immutable member functions

Simen kjaeraas simen.kjaras at gmail.com
Mon Jan 24 08:10:37 PST 2011


Jonathan M Davis <jmdavisProg at gmx.com> wrote:

>> Only to humans. const applies to everything after it, unless there
>> are parentheses. In this case, 'everything' is Foo bar();
>
> Not quite right. The return value is _not_ const in this case. It's
> only the function which is affected. Try it and you'll see. The _only_
> time that a return value is const or immutable is if you use parens to
> mark it that way.

I could probably have worded that more clearly.

*clears throat*
const applies to one, and exactly one, thing after it, matched greedily.

So yes, Foo bar() is the 'everything'. Foo and Foo bar() would be two
things.

-- 
Simen


More information about the Digitalmars-d mailing list