Like getClass()
Sergey Gromov
snake.scaly at gmail.com
Sat Sep 27 17:42:15 PDT 2008
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.
More information about the Digitalmars-d-learn
mailing list