Cannot have properties on const references?

Jonathan M Davis jmdavisProg at gmx.com
Sat Sep 24 14:05:40 PDT 2011


On Saturday, September 24, 2011 20:19:43 Andrej Mitrovic wrote:
> On 9/24/11, simendsjo <simendsjo at gmail.com> wrote:
> > struct S {
> > 
> >      @property int B() {
> >      
> >          return 1;
> >      
> >      }
> > 
> > }
> 
> I've reported the error message just recently because it's very
> uninformative. But the solution is to add const to your property
> function:
> 
> struct S {
>      @property int B() const {
>          return 1;
>      }
> }

Property functions are still functions. A member function must be const for it 
to be callable on a const object. But that error message is horrible.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list