opEquals footprint
    Erik Rasmussen 
    i_am_erik at yahoo.com
       
    Wed Mar 22 07:23:34 PST 2006
    
    
  
xs0 wrote:
> int opEquals(Object)
> 
> so it overrides the default implementation found in, you guessed it, 
> Object :) Same goes for opCmp, I think..
> 
> 
> xs0
So what's the best way to actually check the type in the opEquals/opCmp 
method?  Something like...
class A
{
   int opEquals(Object o)
   {
     // check for null
     if(o is null)
       return false;
     // check type
     if(typeid(typeof(o)) != typeid(A))
       return false;
     // cast
     A that = cast(A) o;
     // actually check fields
     return this.a == that.a && this.b == that.b && ...;
   }
}
Or is there a better way?  asserts?
How do you hard-core D programmers usually do it?
Cheers,
Erik
    
    
More information about the Digitalmars-d-learn
mailing list