const/immutable member functions
Jonathan M Davis
jmdavisProg at gmx.com
Mon Jan 24 06:21:31 PST 2011
On Monday 24 January 2011 06:02:13 Simen kjaeraas wrote:
> Trass3r <un at known.com> wrote:
> > class F
> > {
> > const Foo bar();
> > }
> >
> > Isn't this ambiguous? "returns a const Foo object" vs. "is a const
> > member function that returns a Foo object"?
>
> 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.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list