How to get runtime type of this?

Zhouxuan pycerl at qq.com
Fri Oct 4 01:03:22 PDT 2013


import std.stdio;

class A
{
	static int id = 0;
	this()
	{
		writeln("typeid=", typeid(this));
		writeln("id=",typeof(this).id); //how to get runtime type of 
this ??
	}
}

class B : A
{
	static int id = 1;
}

class C : A
{
	static int id = 2;
}

void main()
{
	A a = new B;
	A b = new C;
}

typeof(this) can get compile time type while typeid yield a 
runtime TypeInfo instance, but how to get runtime type? I want 
the output to be "id=1" and "id=2" respectively.


More information about the Digitalmars-d-learn mailing list