overiding mutable methods in immutable classes
    Eric via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Fri Nov 21 16:24:37 PST 2014
    
    
  
immutable class X
{
    private int x;
    this(int x) { this.x = x; }
    ...
    override size_t toHash(); // error: can't override mutable 
method
}
Since toHash() cannot be overridden in an immutable class,
is there a work-around?
In other words,
immutable X x1 = new immutable X(5);
immutable X x2 = new immutable X(5);
I would like for x1.toHash() to equal x2.toHash(),
but this is not the case because toHash() cannot be overridden.
Note also that (x1 != x2) even though they should be equal (I 
think...)
Is this a bug or a feature?
-Eric
    
    
More information about the Digitalmars-d-learn
mailing list