opAssign and const?

Jonathan M Davis jmdavisProg at gmx.com
Thu May 3 23:48:25 PDT 2012


On Friday, May 04, 2012 08:32:40 Era Scarecrow wrote:
> On Friday, 4 May 2012 at 06:15:21 UTC, Jonathan M Davis wrote:
> > I believe that the issue is that x2 isn't const, so when the
> > compiler decides which of the two overloads to use, it picks
> > the one which doesn't use const. If the const ref version were
> > the only one, then it would work with x2, but since it isn't,
> > the other one gets picked because it's deemed a better match.
> 
>   I figured that was the case too. But I get the feeling that's
> wrong in this case. I was hoping to have only two declared
> opAssing's, one for temporaries (without ref) and one for
> copying. Kinda like the difference between saying a=b and a[]=b[]
> for an array. Be annoying if I had to force the cast to be const
> to do what I wanted; Right?

If you make the one which isn't a ref const as well, it'll probably work.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list