[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #32964] Inheritance and anonymous functions do
From: |
Patrick Häcker |
Subject: |
[Octave-bug-tracker] [bug #32964] Inheritance and anonymous functions do not work together |
Date: |
Thu, 31 Mar 2011 11:20:00 +0000 |
User-agent: |
Mozilla/5.0 (compatible; Konqueror/4.4; de) KHTML/4.4.5 (like Gecko) |
Follow-up Comment #1, bug #32964 (project octave):
I cannot see the full text of my previous entry in the browser, so I repost it
without using verbatim:
There is a problem in Octave with the combination of inherited objects and
the
usage of anonymous functions/methods, which works with Matlab. It's probably
best to give an example:
Assume there is a class "Parent":
Constructor:
function parent = Parent()
parent = class(struct(), 'Parent');
end
Method:
function parentMethod(parent)
disp(['This is a method of class Parent called with an object of class '
class(parent)]);
end
Assume there is another class "Child" which inherits from "Parent":
Constructor:
function child = Child()
child = class(struct(), 'Child', Parent());
end
Now we want to test our two classes:
function testInheritance()
% This works in Matlab and in Octave
child = Child();
parentMethod(child);
% This works, too
parent = Parent();
fun = @() parentMethod(parent);
fun();
% This works in Matlab but not in Octave
fun = @() parentMethod(child);
fun();
end
The result of this test is:
This is a method of class Parent called with an object of class Child
This is a method of class Parent called with an object of class Parent
error: parentMethod: no method for class Child
So as you can see, the call of the parent method fails for inherited objects
when using an anonymous function. Thus it's not possible to use higher order
functions with inheritance in Octave. I attached the code as an tar file.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?32964>
_______________________________________________
Nachricht geschickt von/durch Savannah
http://savannah.gnu.org/