Wed 05 Jan 2011 03:50:57 PM UTC, original submission:
Accessing fields of an object should be done directly from within a method (ie not calling subsref/subsasgn): while this is the case for a public class method and for a private class method (see:
https://savannah.gnu.org/bugs/?30909), it is not for a subfunction of a private class method.
This can be reproduced with the following code:
==================== @testclass/testclass.m ====================
function obj = testclass(varargin)
obj = struct('public',1, 'private',0);
obj = class(obj,'testclass');
==================== @testclass/subsref.m ====================
function dat = subsref(obj,subs)
switch subs.type
case '.'
switch subs.subs
case 'public'
%dat = obj.param;
dat = param(obj);
otherwise
error('err');
end
otherwise
error('err');
end
==================== @testclass/private/param.m ====================
function dat = param(obj)
%dat = obj.public; % direct access => works
dat = param2(obj); % => subfunction calls subsref => crash
function dat = param2(obj)
dat = obj.public; % calls subsref...
========================================
octave> a = testclass;
octave> a.public
results in an infinite loop param<->subsref in Octave, while this works as expected in MATLAB.
|