Member not accessible in delegate body

John C via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 23 00:54:15 PDT 2016


If I try to call the protected method of a superclass from inside 
the body of a delegate, the compiler won't allow it.

void layoutTransaction(Control c, void delegate() action) {
   // do stuff
   action();
   // do more stuff
}

class Control {
   protected void onTextChanged() {}
}

class Label : Control {
   protected override void onTextChanged() {
     layoutTransaction(this, {
       super.onTextChanged(); // <--- Error here
       changeSize();
     });
   }
   private void changeSize() {}
}

Output: class Control member onTextChanged is not accessible.

How is it possible that "onTextChanged" isn't accessible but the 
private method "changeSize" *is*?


More information about the Digitalmars-d-learn mailing list