On Thu, 19 Mar 2009 06:20:40 -0400, Steve Teale
<[email protected]> 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