Like getClass()
Denis Koroskin
2korden at gmail.com
Sun Sep 28 14:12:45 PDT 2008
On Sun, 28 Sep 2008 04:42:15 +0400, Sergey Gromov <snake.scaly at gmail.com>
wrote:
> Sat, 27 Sep 2008 19:21:56 -0400,
> Christopher Wright wrote:
>> 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.
>
> I'd say it's a bug. Classinfo is for runtime class, and runtime class
> can never be an interface.
Do all IUknown interface instances have classinfo member? That's not a bug
if they don't. That's the same reason why interfaces can't be casted to
Object.
More information about the Digitalmars-d-learn
mailing list