D1/D2: How to check if a method has been overridden

klickverbot see at klickverbot.at
Tue Sep 7 14:00:14 PDT 2010


Hello all,

as some of you might know, I have started working on a D module for SWIG 
quite some time ago. In the meantime, the project is almost ready for 
inclusion in SWIG trunk as a full-fledged language module supporting 
D1/Tango and D2/Phobos.

However, there is one major blocker left: I need to check if a method 
has been overridden for this in a potential subclass (obviously at 
runtime), as illustrated below.

---
class A {
   void foo( float a ) {}
   void foo( int a ) {}

   final void bar() {
     // Determine whether this.foo( 1 ) and this.foo( 1f ) really refer
     // to A.foo( float ) and A.foo( int ) or if they point to a subclass
     // implementation – how?
   }
}

class B : A {
   override void foo( float a ) {}
}

class C : A {
   override void foo( int a ) {}
}

class D : B {
   override void foo( int a ) {}
}
---

Until DMD 1.047, I have used a piece of code shown in 
http://d.puremagic.com/issues/show_bug.cgi?id=4835, but the casts in 
there are no longer enough for DMD to determine which overload is being 
referred to.

Now, please tell me that there _is_ a way to do this (D1 and D2, but I 
don't mind if have to generate different code for the both)…


More information about the Digitalmars-d mailing list