digitalmars.D - typeof reference to class object
- Steve Teale <steve.teale britseyeview.com> Mar 19 2009
- Gide Nwawudu <gide btinternet.com> Mar 19 2009
import std.stdio;
class A
{
int a;
}
class B
{
int b;
}
void main()
{
int n;
Object a = new A;
Object b = new B;
writefln("%s %s %s", typeof(n).stringof, typeof(a).stringof,
typeof(b).stringof);
}
prints int Object, Object.
This seems somewhat counter-intuitive for an object oriented language!
Mar 19 2009
On Thu, 19 Mar 2009 06:20:40 -0400, Steve Teale <steve.teale britseyeview.com> wrote:import std.stdio; class A { int a; } class B { int b; } void main() { int n; Object a = new A; Object b = new B; writefln("%s %s %s", typeof(n).stringof, typeof(a).stringof, typeof(b).stringof); } prints int Object, Object. This seems somewhat counter-intuitive for an object oriented language!
typeof resolves at compile time, if you want the actual class name you should use classinfo. import std.stdio; class A { int a; } class B { int b; } void main() { int n; Object a = new A; Object b = new B; writefln("%s %s %s", typeof(n).stringof, a.classinfo.name, b.classinfo.name); } Gide
Mar 19 2009








Gide Nwawudu <gide btinternet.com>