Confused about const

Paul D. Anderson paul.d.removethis. at comcast.andthis.net
Fri Mar 19 21:33:59 PDT 2010


After further review, I now realize that the right way (for me) to do this is to add a .dup property. So instead of 

S foo(const S s) {
    S other;
    other = s;
}

or

S foo(const S s) {
    S other = S(s);
    return other;
}

which didn't look right to me, I can write

S foo(const S s) {
    S other = s.dup;
    return other;
}

which is ultimately an equivalent operation.

Thanks again, everyone for taking the time to explain what was going on.

Paul

It just looks better to me.





Paul D. Anderson Wrote:

> bearophile Wrote:
> 
> > The idea now is to find a way to encapsulate that manual copying & dupping into some overloaded operator of S. But I have failed so far. Operator overloading in D2 is not an easy thing, it needs training. (That's why I have recently asked for the compiler to be strict to avoid wrong usages of the operator overloading.)
> > 
> > Bye,
> > bearophile
> 
> 
> So I understand better now, thanks, what is wrong. I'm a little disappointed that there is apparently no way to implement case 4 for any struct with a reference.
> 
> Paul



More information about the Digitalmars-d-learn mailing list