interface and opEquals
    Oliver 
    oliver.ruebenkoenig at web.de.REMOVE
       
    Sun Nov  4 09:58:24 PST 2007
    
    
  
Hi everyone,
the following code works and does what it is supposed to do. I am, however, unsure if this is the "right" way to do it. I read somewhere that opEquals should take an Object as argument. I can not get the code to work with Object as argument. Can anyone explain this to be, what am i missing? Thanks to everyone,
Oliver
------------------------
import std.stdio;
interface Vi {
    void f();
    int opEquals( Vi );
    //int opEquals( Object );
    //int opEquals();
}
class C1 : Vi {
    void f() { writefln( "C1: ", itsInt ); }
    this( int i ) { this.itsInt = i; }
    int opEquals( Vi o ) { 
        C1 test = cast(C1)o;
        return test && this.itsInt == test.itsInt;
    }   
    //int opEquals( C1 test ) { return this.itsInt == test.itsInt; }
private:
    int itsInt;
}
int main() {
    assert( 1 == 1.0 );
    Vi myInt1 = new C1(1);
    Vi myInt2 = new C1(1);
    myInt1.f();
    assert( cast(C1)myInt1 == cast(C1)myInt2 );
    assert( myInt1 == myInt2 );
    return 0;
}
    
    
More information about the Digitalmars-d-learn
mailing list