Effacer les filtres
Effacer les filtres

Class Hierarchy Constructor Syntax - Include all inherited properties;

1 vue (au cours des 30 derniers jours)
CustomBuilt
CustomBuilt le 8 Sep 2016
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.

Réponses (1)

Steven Lord
Steven Lord le 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);

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by