octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Classdef test required on Matlab


From: Michael Goffioul
Subject: Re: Classdef test required on Matlab
Date: Mon, 20 Jan 2014 00:17:41 -0500

On Sun, Jan 19, 2014 at 10:14 PM, fgnievinski <address@hidden> wrote:
Michael Goffioul wrote
> On Sun, Jan 19, 2014 at 12:36 PM, Lukas Reichlin <

> lukas.reichlin.lists@

>> wrote:
>
>> On 19.01.2014, at 17:42, Michael Goffioul &lt;

> michael.goffioul@

> &gt;
>> 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

clA::subsref is being reached directly from runAll, not through method
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


Of course. By overloading subsref, I inadvertently killed the dot-notation, so I was actually not calling getPropFromA. Thanks for pointing this out.

Would you mind running the test with this modified runAll.m?

Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]