Like getClass()

Christopher Wright dhasenan at gmail.com
Sat Sep 27 16:21:56 PDT 2008


Sergey Gromov wrote:
> Sat, 27 Sep 2008 19:50:18 +0200,
> torhu wrote:
>> obj.classinfo doesn't work the way you'd expect with an interface, but 
>> it works when you've got an object:
>>
>> writefln((cast(Object)thing).classinfo.name);
> 
> Thanks for the tip!  It seems like classinfo of an interface contains 
> information about the most derived interface implemented in an object:
> 
> interface a {}
> interface aa : a {}
> class A : aa {}
> void main() {
>     writefln((cast(a) new A).classinfo.name);
> }
> 
> prints "test.aa".  Though this functionality is of questionable 
> usefulness (has anybody used it for something?) and besides it's broken:
> 
> interface a {}
> interface aa : a {}
> class A : a, aa {}
> void main() {
>     writefln((cast(a) new A).classinfo.name);
> }
> 
> prints "test.a" even though A implements the "aa" interface as well.

Since .classinfo is essentially a virtual call, and interface vtbls are 
filled from the class's vtbl, it shouldn't in theory be terribly 
difficult to change this. Of course, I'd have to check the dmd source to 
be sure.


More information about the Digitalmars-d-learn mailing list