www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Displaying type of something

reply Georg Wrede <georg.wrede iki.fi> writes:
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.
Mar 09 2009
next sibling parent Lars Kyllingstad <public kyllingen.NOSPAMnet> writes:
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.
typeof(t).stringof -Lars
Mar 09 2009
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Georg Wrede:
 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: ", typeid(typeof(t))); (Try alternatives of that with a dynamic type, like a class). Bye, bearophile
Mar 09 2009
parent Georg Wrede <georg.wrede iki.fi> writes:
bearophile wrote:
 Georg Wrede:
 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: ", typeid(typeof(t))); (Try alternatives of that with a dynamic type, like a class).
Thanks!!! class A { } class B : A { } class C : B { } A a; B b; C c; A ac = new C; Typeof ac is: A So it's the variable, not its current contents. Kinda makes sense.
Mar 09 2009
prev sibling parent reply Christopher Wright <dhasenan gmail.com> writes:
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);
Mar 09 2009
parent Georg Wrede <georg.wrede iki.fi> writes:
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!!
Mar 09 2009