Calling function within class.

Vino akashvino79 at gmail.com
Wed Nov 18 19:25:06 UTC 2020


On Wednesday, 18 November 2020 at 18:24:59 UTC, frame wrote:
> On Wednesday, 18 November 2020 at 17:55:36 UTC, Vino wrote:
>
>>
>>   I made the changes as below , still not working
>>
>> auto fltask = task!listFile(st);
>> to
>> auto fltask = 
>> task!({listFile(st);})(this).executeInNewThread();
>
> The syntax is just wrong:
>
> auto fltask = task!({listFile(st);})(this).executeInNewThread();
>
> Should be:
>
> auto fltask = task!((GetDirlist 
> obj){obj.listFile(st);})(this).executeInNewThread();
>
> It's the anonymous function syntax in one line compressed - 
> it's equal to:
>
> auto fltask = task!(
>   function(GetDirlist obj) {
>      obj.listFile(st);
>   }
> )(this).executeInNewThread();
>
>
> But with your context it must look like this:
>
> auto fltask = task!(
>   function(GetDirlist obj, string foo) {
>      obj.listFile(foo);
>   }
> )(this, st);
>
> Still your code need to be fixed at lot to get working.

Hi,

   The above code is a sample code, but the logic is same, correct 
me if my understanding is wrong, in the above code "obj" is a an 
object for the class GetDirlist, so we are accessing the class 
member using "obj.listFile(st)" , so why do we need the "(this)" 
and also why is this so complicated in D where as in PHP it is 
simple like below

PHP Code:
class PHPclass {
       function test1 ($st) { return $st; }
       function test2 ()  { return $this->test1("Test"); }
}

$obj = new PHPclass();
print_r($obj->test2());







More information about the Digitalmars-d-learn mailing list