immutability and constness
Minas Mina
minas_mina1990 at hotmail.co.uk
Thu Jul 12 17:49:49 PDT 2012
On Thursday, 12 July 2012 at 14:42:17 UTC, Ali Çehreli wrote:
> On 07/12/2012 07:13 AM, Minas wrote:
>> Thanks a lot!
>> So what is the problem with (logical)const? Is it needed that
>> much? And why some methods (toString(), toHash()) HAVE to be
>> const? I mean, what's the problem if they aren't?
>
> Here is the problem:
> ....
> (That is why I almost never make abstract member functions
> 'const' in my C++ coding. Base can't know mutability needs of
> the derived.)
> Ali
I see. Just because toString() in object is const, so must be in
the derived classes thus limiting them.
So now I understand the solution that Andrei is considering
(removing those from object). I think this is a good thing to do,
those functions don't belong there (I have had some experience
with Java's equals(Object o). All I say is that it sucks.)
In C++, I would use a templated function. If the type didn't
provide those methods it would be a compile error. Nice and clean
:)
Thanks for the reply :)
More information about the Digitalmars-d-learn
mailing list