|
From: | Michael Goffioul |
Subject: | Re: Classdef test required on Matlab |
Date: | Mon, 20 Jan 2014 00:17:41 -0500 |
Michael Goffioul wrote
> On Sun, Jan 19, 2014 at 12:36 PM, Lukas Reichlin <>> wrote:
> lukas.reichlin.lists@
>
>> On 19.01.2014, at 17:42, Michael Goffioul <
> michael.goffioul@
> >
clA::subsref is being reached directly from runAll, not through method>> wrote:
>>
>> > Could someone test the following in Matlab? Put all files into a single
>> dir, then run "runAll".
>> >
>> > Thanks,
>> > Michael.
>> >
>> >
> <clA.m>
> <clB.m>
> <clC.m>
> <runAll.m>
>>
>> Here you go :-) R2013a on a Mac.
>>
>> Cheers,
>> Lukas
>>
>> >> runAll
>> >>> calling aa.getPropFromA
>> >>> clA::subsref
>>
>> ans =
>>
>> 10
>>
>> >>> calling bb.getPropFromA
>> >>> clA::subsref
>>
>> ans =
>>
>> 10
>>
>> >>> calling bb.getPropFromB
>> >>> clA::subsref
>>
>> ans =
>>
>> 10
>>
>> >>> calling cc.getPropFromC
>> >>> clA::subsref
>>
>> ans =
>>
>> 10
>>
>> >>
>
>
> Thanks. However, this is rather unexpected. I was reading documentation
> about overloading subsref [1] and the documentation says that built-in
> subsref is always called from withing class methods. So unless I'm
> mis-reading the doc, the first case should at least not have called
> clA::subsref. This doesn't make sense...
>
> Michael.
>
>
> [1]
> http://www.mathworks.com/help/matlab/matlab_oop/indexed-reference-and-assignment.html#br09nsm
getPropFromA.
modifying subsref as follows:
function y = subsref (this, S)
disp('>>> clA::subsref');
display(dbstack(1))
display(S)
y = this.prop;
end
shows that:
>>> calling aa.getPropFromA
>>> clA::subsref
file: 'runAll.m'
name: 'runAll'
line: 5
S =
type: '.'
subs: 'getPropFromA'
ans =
10
on the other hand, calling the method explicitly,
does NOT reach the overload subsref, as expected:
>> getPropFromA(aa)
ans =
10
[Prev in Thread] | Current Thread | [Next in Thread] |