How will we fix opEquals?
Jonathan M Davis
jmdavisProg at gmx.com
Thu Feb 10 22:13:55 PST 2011
On Thursday 10 February 2011 21:50:45 so wrote:
> > We _must_ have it there, so anyone overriding those functions _must_
> > use it for those functions. They could create non-const versions in
> > addition to
> > the const ones,
>
> It is the whole point, they can't.
Hmm. You're right (I just tried it). I was certain that you could. It's the kind
of thing that you could do in C++, but I guess that D is pickier about
overriding. You can certainly _add_ const, but I guess you can't take it away
even if there's also a const version defined. I guess that part of the problem is
that I so rarely use classes in D. I usually use structs. I'm sure that will
change if I ever get the chance to write large programs in D, but until I can
use it at work I'm not sure how likely that is.
Well, then there's no caching of toHash unless you call a separate function to
calculate and cache the result first, or you use a global variable to hold the
cached value. That kind of sucks, but I think that const is far more valuable
that the possibility of caching, and there _are_ ways to get the caching
behavior in spite of const - they just aren't all that nice.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list