get type name from current class at compile time?

Jack jckj33 at gmail.com
Sun Apr 25 01:50:50 UTC 2021


```d
class A
{
	void showMyName()
	{
		writefln("name = [%s]", __traits(identifier, typeof(this)));
	}
}

class K : A { }
```

then

```d
new K().showMyName();
```

output:

name = [A]

I'd like to output `K` and get this identifier at compile time. 
But I'd to do so automatically so rule out something like:

```d
class A
{
	string name = __traits(identifier, typeof(this));

	void showMyName()
	{
		writefln("name = [%s]", name);
	}
}

class K : A
{
	this()
	{
		super.name = __traits(identifier, typeof(this));
	}
}
```





More information about the Digitalmars-d-learn mailing list