typeof(this) return wrong type

Andrey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 22 05:51:08 PDT 2017


On Saturday, 22 April 2017 at 12:43:41 UTC, Andrey wrote:
> On Saturday, 22 April 2017 at 12:23:32 UTC, Basile B. wrote:
>> On Saturday, 22 April 2017 at 11:45:54 UTC, Andrey wrote:
>> use a "template this" parameter:
>>
>> void onCreate(this T)()
>> {
>>     writeln(getSymbolsByUDA!(T, OnClickListener).stringof);
>> }
>>
>> if possible. The problem is not solved if onCreate is not 
>> called on the most derived.
>
> It works if I explicitly specify the type:
>> MyView v2 = new MyView();
>> v2.onCreate();  // Works well, using MyView type
>> void test(View v) {
>>     v.onCreate();  // using View type :(
>> }

But this working well:
> this(this T)() {
>     writeln(T.stringof);
> }
It suits me, thanks a lot!


More information about the Digitalmars-d-learn mailing list