Default method in class defintion

Hello all, I’m lately building alot of classes for different communication engineering in octave. However is there a way to introduce a “deafult” method in the class defintion if the method was not specified in the class definiton. So instead of getting the error " error: subsref: unknown method or property" the program will jump in the default method.

Depending on the class design, inheritance might be an option.

classdef myDefault
    function r = subsref (obj, s)
      r = 'default';


classdef myClassWithDefault < myDefault

In action (Octave 6.4.0):

>> a = myDefault;
>> a.something
ans = default
>> b = myClassWithDefault;
>> b.something
ans = default

Thanks for your response and especially pointing me to the use of subsref. This solution is working perfectly in my case :slight_smile:

1 Like