|
Matt schreef:
> PP <pp@pp.com> wrote in message <hebiuk$1go$1@news.eternal-september.org>...
>> Hello,
>>
>>
>> I wish to do a trick with abstract classes an inheritance. I create an
>> abstract class:
>>
>> classdef compare
>> methods (Abstract)
>> lt(a,b)
>> eq(a,b)
>> end
>> methods
>> function r=ne(a,b)
>> r=~eq(a,b);
>> end
>> function r=le(a,b)
>> r=eq(a,b)||lt(a,b);
>> end
>> function r=gt(a,b)
>> r=~lt(a,b)&&~eq(a,b);
>> end
>> function r=ge(a,b)
>> r=~lt(a,b);
>> end
>> end
>> end
>>
>> and then I implement a concrete class:
>>
>> classdef C < compare
>> methods
>> function r=lt(a,b)
>> ...
>> end
>> function r=eq(a,b)
>> ...
>> end
>> end
>> end
>>
>> so that the other comparing function are inherited. Matlab is not
>> complaining when doing this, but using the debugger I see that the
>> methods in the superclass are not called. What am I doing wrong?
>
> It works fine for me. What is happening instead, precisely?
>
> One thing that might be playing a role here is that you are using short-circuited relational operators || and &&. This means for example that in the expression
>
> r=eq(a,b)||lt(a,b);
>
> lt(a,b) will never be called if eq(a,b) evaluates true.
>
> BTW, the short-circuited operators are almost certainly not what you want to use. It means your methods can only be used when eq(a,b) and lt(a,b) return scalars.
Today it started working magically? In this instance scalars are
returned, but I made a comment in my code about the possible problem for
future users, thanks for pointing this out.
Regards
|