Getting most derived type of object that implements interface

cc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 25 01:54:35 PDT 2016


I'm having trouble getting the full name of an object of a class 
that implements an interface, using typeid() or .classinfo, the 
behavior seems to be different from that of a class that simply 
derives other classes.

interface FooInterface {}
class BarImplementsInterface : FooInterface {}

class FooBaseClass {}
class BarDerivedClass : FooBaseClass {}

void main() {
	FooInterface a = new BarImplementsInterface();
	FooBaseClass b = new BarDerivedClass();
	writefln("a class: %s", a.classinfo.name);
	writefln("b class: %s", b.classinfo.name);
}

Output:
a class: test.FooInterface
b class: test.BarDerivedClass


I expected "a class: test.BarImplementsInterface" as the result 
output.. Am I expecting the wrong behavior?  Is there a preferred 
way to do this?


More information about the Digitalmars-d-learn mailing list