const method and return type

Adam D. Ruppe destructionator at gmail.com
Fri Dec 13 16:01:30 PST 2013


On Friday, 13 December 2013 at 23:46:14 UTC, Andrea Fontana wrote:
> class A
> {
>     auto getter() const
>     {
>         return property;
>     }
>
>     int property = 0;
>
> Why this method return "const int"?

Inside getter, "this" is const. Due to transitive const, all the 
members through this are const too.

So inside getter, property is a const int. The auto return value 
returns the *exact* type, thus const.


More information about the Digitalmars-d-learn mailing list