[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
error using subsref and oop
From: |
Bertrand Roessli |
Subject: |
error using subsref and oop |
Date: |
Mon, 27 Apr 2009 15:47:29 +0200 |
Hello,
I used the new oop feature in Octave that I am trying to
learn.
For this function (found on the web) in the directory @date
function [obj] = date(minute, hour, day, month, year)
% constructor saved in file date.m
obj = struct;
obj.minute = []; % leave blank for whatever reason
obj.hour = hour;
obj.day = day;
obj.month = month;
obj.year = year;
obj = class(obj,'date');
end
I can overload the operator "." by writing another function
function [value] = subsref(obj, S)
idx.type=S.type;
idx.subs={S.subs};
switch idx.type
case '.'
switch idx.subs{:}
case 'minute'
value=obj.minute;
case 'hour'
value=obj.hour;
...
endswitch
endswitch
end
which works fine
octave:2> min=obj.minute;
octave:3> min
min = [](0x0)
octave:4> min=obj.hour;
octave:5> min
min = 2
However, using
builtin('subsref', obj, idx)
in
function [value] = subsref(obj, S)
idx.type=S.type;
idx.subs={S.subs};
value = builtin('subsref', obj, idx);
end
results in an error in octave-3.1.55
octave:9> obj=date(12,2,3,11,2008);
octave:10> min=obj.hour;
error: max_recursion_limit exceeded
What did I do wrong?
Thank you in advance,
Bertrand Roessli
- error using subsref and oop,
Bertrand Roessli <=