Member not accessible in delegate body

Martin Nowak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 23 11:20:24 PDT 2016


On Friday, 23 September 2016 at 07:54:15 UTC, John C wrote:
> 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*?

Please file a bug report issues.dlang.org, shouldn't be difficult 
to fix.


More information about the Digitalmars-d-learn mailing list