get type name from current class at compile time?

Jack jckj33 at gmail.com
Sun Apr 25 03:45:13 UTC 2021


On Sunday, 25 April 2021 at 02:45:38 UTC, Paul Backus wrote:
> On Sunday, 25 April 2021 at 02:26:00 UTC, Jack wrote:
>>
>> doesn't this work when called from member in a derived class?
>>
>> ```d
>>
>> class A
>> {
>> 	void doSomething(this T)()
>> 	{
>> 		writefln("name = [%s]", __traits(identifier, T));
>> 	}
>> }
>>
>> class K : A
>> {
>> 	void baa()
>> 	{
>> 		doSomething();
>> 	}
>> }
>> ```
>>
>> result in the error:
>>
>> Error: template `foo.A.doSomething` cannot deduce function 
>> from argument types `!()()`,
>
> It works if you call it with `this.doSomething()`: 
> https://run.dlang.io/is/eIygNG

that's better, thanks


More information about the Digitalmars-d-learn mailing list