Clear Filters
Clear Filters

Class Hierarchy Constructor Syntax - Include all inherited properties;

1 view (last 30 days)
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.

Answers (1)

Steven Lord
Steven Lord on 8 Sep 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);

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!