I have a class A with members a,b,c, and a class B which inherits from class A. Class B has members d,e,f as well.
Class B has a variable argument constructor; you can pass it another class B and it attempts to initialize a,b,c like so:
B = B@A( varargin{1} );
Alternately, you can specify members a-f explicitly, in which case:
B = B@A( varargin{1:3} );
(A's constructor is written to handle both as well).
However, when I run my code, I get the error message that you can only call the superclass constructor from the top-level (I suppose not in the if statement). Is there some other way to get this functionality?
My revised constructor for class B looks like this:
if nargin == 1
bInstance = varargin{1};
superclass_args = { bInstance };
elseif nargin == 3
superclass_args = varargin{1:3}
end
newB = B@A( superclass_args{:} );
if nargin == 1
(assign d,e,f from bInstance)
if nargin == 3
(assign d,e,f from varargin)
end
A bit convoluted, but at least it works.