How to pass a superclass method as a calback?

1 visualización (últimos 30 días)
Mario Koddenbrock
Mario Koddenbrock el 7 de Dic. de 2017
Comentada: Guillaume el 7 de Dic. de 2017
Does anybody know how to pass a superclass function as a calback?
For example a button callback:
btn = uicontrol('Style', 'pushbutton', 'String', 'Example',...
'Position', [20 20 50 20],...
'Callback', @(~, ~)methodFromSuperclass@superclass(obj));
But this one gives an error:
"@" Within a method, a superclass method of the same name is called by saying method@superclass. The left operand of "@" must be the method name.
Thanks, Mario

Respuesta aceptada

Mario Koddenbrock
Mario Koddenbrock el 7 de Dic. de 2017
Okay I found the solution:
btn = uicontrol('Style', 'pushbutton', 'String', 'Example',...
'Position', [20 20 50 20],...
'Callback', @(~, ~)obj.methodFromSuperclass());
if the methodFromSuperclass is not used in the subclass.
  1 comentario
Guillaume
Guillaume el 7 de Dic. de 2017
Yes, the @ syntax is only used
  • in the constructor when you want to call the superclass constructor
  • in a class method when you want to invoke a superclass method that has been overriden in the class.
It is never used by a user of the class. The whole point of inheritance is that all methods from all superclasses appear as normal methods of the derived class, so from a user point of view, either
obj.inheritedmethod() %dot notation
or
inheritedmethod(obj) %functional notation
works.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Assembly en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by