[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #52614] setting properties of classdef object
From: |
Amro |
Subject: |
[Octave-bug-tracker] [bug #52614] setting properties of classdef object during construction with inheritance |
Date: |
Thu, 7 Dec 2017 10:56:20 -0500 (EST) |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 |
URL:
<http://savannah.gnu.org/bugs/?52614>
Summary: setting properties of classdef object during
construction with inheritance
Project: GNU Octave
Submitted by: amro_octave
Submitted on: Thu 07 Dec 2017 05:56:19 PM EET
Category: Interpreter
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Unexpected Error
Status: None
Assigned to: None
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 4.2.1
Operating System: Any
_______________________________________________________
Details:
I have a simple class hierarchy with two classes:
* In the base class, the constructor calls a method which initializes some
properties.
* In the derived class, I override said method (while still calling the parent
method). The constructor also invokes the parent constructor.
Here is a minimal example:
$ cat ClassA.m
classdef ClassA < handle
properties
a
end
methods
function obj = ClassA()
disp('-- ClassA.ClassA')
obj.foo();
end
function foo(obj)
disp('-- ClassA.foo')
obj.a = 1;
end
end
end
$ cat ClassB.m
classdef ClassB < ClassA
properties
b
end
methods
function obj = ClassB()
disp('-- ClassB.ClassB')
obj = address@hidden();
end
function foo(obj)
disp('-- ClassB.foo')
address@hidden(obj);
obj.b = 2;
end
end
end
This works fine in MATLAB (I'm using R2017a):
>> obj = ClassA()
-- ClassA.ClassA
-- ClassA.foo
obj =
ClassA with properties:
a: 1
>> obj = ClassB()
-- ClassB.ClassB
-- ClassA.ClassA
-- ClassB.foo
-- ClassA.foo
obj =
ClassB with properties:
b: 2
a: 1
But it fails in Octave 4.2.1:
>> obj = ClassA()
-- ClassA.ClassA
-- ClassA.foo
obj =
<object ClassA>
>> obj = ClassB()
-- ClassB.ClassB
-- ClassA.ClassA
-- ClassB.foo
-- ClassA.foo
error: cannot reference properties of class `ClassB' for non-constructed
object
error: called from
foo at line 15 column 19
ClassA at line 9 column 13
ClassB at line 9 column 17
I did try to incorporate the functionality of the foo method into the
constructor (i.e directly set the properties a and b from the respective
constructors), and the code does work then (both MATLAB and Octave):
$ cat ClassAA.m ClassBB.m
classdef ClassAA < handle
properties
a
end
methods
function obj = ClassAA()
disp('-- ClassAA')
obj.a = 1;
end
end
end
classdef ClassBB < ClassAA
properties
b
end
methods
function obj = ClassBB()
disp('-- ClassBB')
obj = address@hidden();
obj.b = 2;
end
end
end
Still, I wanted to report this case... Thanks.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?52614>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #52614] setting properties of classdef object during construction with inheritance,
Amro <=