Azzera filtri
Azzera filtri

Class Hierarchy Constructor Syntax - Include all inherited properties;

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Steven Lord
Steven Lord il 8 Set 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);

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by