How to run a default method if a class method is undefined?
Afficher commentaires plus anciens
Say I have a class called A.
a=A();
b=A();
If we call foo123(a,5,b,6) and foo123 is not defined, there will be an error.
I'd like to call a default method in the class that will receive the arguments function's name "foo123" and its arguments (a, 5, b and 6) as varargin.
Is there a way to do so?
I have a class that often needs to handle unknown method calls. Having this would make my life much better. Thanks.
1 commentaire
covariant_cat
le 24 Fév 2018
Modifié(e) : Guillaume
le 24 Fév 2018
Réponses (1)
Benjamin Kraus
le 24 Fév 2018
Modifié(e) : Benjamin Kraus
le 24 Fév 2018
I don't believe there is any way to do this when using the syntax you describe. However, if you use the dot notation, then you can process arbitrary inputs.
foo123(a,5,b,6); % No way to implement desired behavior
a.foo123(5,b,6); % This can be implemented for arbitrary method names.
1 commentaire
covariant_cat
le 24 Fév 2018
Modifié(e) : per isakson
le 4 Mar 2018
Catégories
En savoir plus sur Execution Speed dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!