const/immutable member functions

Jens Mueller jens.k.mueller at gmx.de
Mon Jan 24 06:28:16 PST 2011


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();
> 
> I do agree it is ambiguous though, and should be disallowed, or at
> very least, discouraged.

Very true.
Preferred style is to write
Foo bar() const;

Jens


More information about the Digitalmars-d mailing list