Multiple alias this is coming.

Ali Çehreli via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Sep 18 15:20:04 PDT 2014


On 09/18/2014 12:52 PM, bearophile wrote:

 > Can someone show one or more usage cases?

I can't claim that I have experience with multiple alias this ;) but I 
like the following example that I had come up with:

class TeachingAssistant
{
     Student studentIdentity;
     Teacher teacherIdentity;

     this(string name, string subject)
     {
         this.studentIdentity = new Student(name);
         this.teacherIdentity = new Teacher(name, subject);
     }

     /* The following two 'alias this' declarations will enable
      * this type to be used both as a Student and as a Teacher. */
     alias teacherIdentity this;
     alias studentIdentity this;
}

Ali

[1] http://ddili.org/ders/d.en/alias_this.html



More information about the Digitalmars-d-announce mailing list