How a class can know the current reference of itself?

Pippo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Aug 4 02:38:59 PDT 2017


I'm trying to do something like this:

------------
module mylib.classA;

class A
{
   @property string myproperty;
   void function(ref A a) callToMyFunction;

   void myfunction()
   {
     callToMyFunction(ref this);
   }
}

------------
module myapp;

import mylib.classA;

int main()
{
   A a = new A();

   a.callToMyFunction = &myFunction;

   a.myfunction();
}

void myFunction(ref A a)
{
   writefln(a.myproperty);
}

------------

but (clearly) cannot compile. How can I get the same result?

Thank you in advance.


More information about the Digitalmars-d-learn mailing list