In a class constructor, if I call another method to initialize some property, why that property not changed?
Example code:
classdef Test
properties
prop
end
methods
function obj = Test()
obj.init();
end
function init(obj)
obj.prop = 1;
end
end
end
Then by executing A = Test(); I got A.prop = [].
classdef Test < handle
This will apply methods to the referenced object.
You have to return the modified object:
function obj = Test()
obj.init();
end
should be
function obj = Test()
obj = obj.init();
end
However, your init() is also not returning the modified object to the caller:
function init(obj)
obj.prop = 1;
end
which should be
function obj = init(obj)
obj.prop = 1;
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With