Getting a class' name, but not fully qualified?

Matt webwraith at fastmail.fm
Sun Mar 30 09:26:47 PDT 2014


On Friday, 28 March 2014 at 13:38:01 UTC, Dicebot wrote:

> .classinfo name is name for actual class instance referenced 
> from the variable it was applied to. It happens to be fully 
> qualified but key difference here is that it uses RTTI 
> (run-time type information) to access "real" type of 
> polymorphic entity.

Thanks for the clarification, Dicebot. Does it mention those 
points in the docs, because I don't remember seeing them? So we 
could be looking at something closer to:

   import std.string;
   import std.stdio;

   class Foo{
     int a;
   }

   class Bar: Foo{
     int b;
   }

   void main(){
     Foo bar = new Bar();
     writeln ("class name: " ~ 
bar.classinfo.name[bar.classinfo.name.lastIndexOf(".") .. $].dup);
   }

if I'm correct?


More information about the Digitalmars-d-learn mailing list