How are objects converted from one type to another when collected together in an array in MATLAB 7.6 (R2008a)?
Show older comments
I have a handle class "SuperClass" and a class "SubClass" which derives from SuperClass, with the following definitions:
classdef SuperClass < handle
properties
prop1
prop2
end
methods
function obj = SuperClass(prop1,prop2)
obj.prop1 = prop1;
obj.prop2 = prop2;
end
end
end
classdef SubClass < SuperClass
properties
newprop
end
methods
function obj = SubClass(prop1,prop2,newprop)
obj = obj@SuperClass(prop1,prop2);
obj.newprop = newprop;
end
end
end
I would like to aggregate objects of these classes into a single vector as follows:
supobj = SuperClass(1,2);
subobj = SubClass(3,4,5);
vec(1) = supobj;
vec(2) = subobj;
Conceptually, this should be possible because subobj is an object of SuperClass. However, this gives me the following error:
??? The following error occurred converting from SubClass to SuperClass:
Input argument "prop2" is undefined.
Accepted Answer
More Answers (0)
Categories
Find more on Construct and Work with Object Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!