www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Deriving opEquals()

reply "Garett Bass" <gtbass studiotekne.com> writes:
Say I have the following interfaces:

  interface Locus {
   int opEquals(Locus that);
  }
  interface Extents {
   int opEquals(Extents that);
  }
  interface Rectangle : Locus, Extents {
   int opEquals(Rectangle that);
  }

Given two objects that implement Rectangle, is there some syntax in D to allow
me to compare their Extents or Locus?  Maybe 
something along the lines of:

    Rectangle r1, r2;
    ...
    if (r1 == cast(Extents)r2) {
        // r1 has the same Extents as r2
        ...

This seems right to me, but I haven't written any OO in D yet.

Thanks,
Garett 
Nov 21 2004
parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
Garett Bass wrote:
 Say I have the following interfaces:
 
   interface Locus {
    int opEquals(Locus that);
   }
   interface Extents {
    int opEquals(Extents that);
   }
   interface Rectangle : Locus, Extents {
    int opEquals(Rectangle that);
   }
 
 Given two objects that implement Rectangle, is there some syntax in D to allow
me to compare their Extents or Locus?  Maybe 
 something along the lines of:
 
     Rectangle r1, r2;
     ...
     if (r1 == cast(Extents)r2) {
         // r1 has the same Extents as r2
         ...
 
 This seems right to me, but I haven't written any OO in D yet.
I haven't actually tried compiling the code above, but it certainly seems reasonable to me. Try compiling it, and tell us what you find!
Nov 22 2004