www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Getting vtable for inherited Interface instance

reply "Kapps" <opantm2+spam gmail.com> writes:
I'm trying to implement a runtime reflection module, and am 
having some issues with figuring out the function pointer to 
invoke an interface on a class that derives from the one that 
implements the interface.

For example, given the following code, we can call an interface 
function using a delegate with http://pastie.org/8255612 - but 
even with the derived instance passed in it will invoke Bar's 
implementation as we're using the function pointer for Bar's 
implementation. I figured typeid(DerivedBar).interfaces would 
return it's own Interface instance for DerivedBar, but it doesn't 
and instead Bar's has to be used. The ABI page doesn't seem to 
mention much about inheriting from a class that implements an 
interface and overrides it's functions. Is there a way for me to 
get the function pointer to the overridden version of foo?
Aug 20 2013
parent "Kapps" <opantm2+spam gmail.com> writes:
I should mention that there's no knowledge of Bar nor DerivedBar 
at compile-time, but there is of Foo. The vtable index of bar 
within Foo is known as well, but without knowledge of Bar or 
DerivedBar I can't just do the same with their implementation.
Aug 20 2013