Class Hierarchy Constructor Syntax - Include all inherited properties;
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have a class with two parents. I am after a simpler constructor method that encapsulates all the inherited properties, example;
classdef signalEcho < signal & target
properties
deltaT
end
properties (Dependent)
EchoCarrierFrequency
EchoDutyCycle
end
methods
function [thisEcho] = signalEcho(thisSignal, thisTarget, deltaT)
thisEcho = thisEcho@signal(thisSignal.CarrierFrequency, thisSignal.PulseRepFreq, thisSignal.DutyCycle);
thisEcho = thisEcho@target(thisTarget.PositionX, thisTarget.PositionY, thisTarget.Velocity, thisTarget.Heading);
if nargin == 3
thisEcho.deltaT = deltaT;
end
end
Would like to replace the constructor with;
methods
function [thisEcho] = signalEcho(thisSignal, thisTarget, deltaT)
thisEcho = thisEcho@signal(thisSignal);
thisEcho = thisEcho@target(thisTarget);
if nargin == 3
thisEcho.deltaT = deltaT;
end
end
When using the above method no inherited data is populated into the the signalEcho object.
0 comentarios
Respuestas (1)
Steven Lord
el 8 de Sept. de 2016
As per the "Initialize Objects Using Multiple Superclasses" section on this documentation page try removing the output argument from your calls to the constructors for the superclasses. So instead of:
thisEcho = thisEcho@signal(thisSignal.CarrierFrequency, thisSignal.PulseRepFreq, thisSignal.DutyCycle);
use:
thisEcho@signal(thisSignal.CarrierFrequency, thisSignal.PulseRepFreq, thisSignal.DutyCycle);
0 comentarios
Ver también
Categorías
Más información sobre Methods en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!