Displaying type of something

Georg Wrede georg.wrede at iki.fi
Mon Mar 9 17:41:18 PDT 2009


Christopher Wright wrote:
> Georg Wrede wrote:
>> When creating templates, it is sometimes handy to print the type of 
>> something. Is there a trivial way to print it?
>>
>>     writeln("Typeof T is: ", typeof(t));
>>
>> This doesn't work, but you get the idea.
> 
> For a class or interface:
> writeln("Typeof T is: ", t.classinfo.name);


     A a;
     B b;
     C c;
     A ac = new C;

     writeln("Typeof T is: ", ac.classinfo.name);

and the result is:

Typeof T is: C

so it really works!!!

Thaks, guys!!



More information about the Digitalmars-d-learn mailing list