フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Argumentsを​使用したクラスコンス​トラクタに関して

2 ビュー (過去 30 日間)
Teppei Iwata
Teppei Iwata 2020 年 8 月 21 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
クラスAのコンストラクタにargumentsを使用しており,クラスBで継承して利用することを検討しております.
その際,クラスAのコンストラクタではオプション引数(options.〇〇)をしています.
クラスBでクラスAのコンストラクタを呼び出す際,どのようにすればよいでしょうか.
classdef ClassA
properties
a;
b;
c;
end
methods
function obj = ClassA(a, options)
arguments
a (1, 1) double
options.b = 1
options.c = 2
end
obj.a = a;
obj.b = options.b;
obj.c = options.c;
end
end
end
classdef ClassB < ClassA
properties
d;
end
methods
function obj = ClassB(a, options)
arguments
a (1, 1) double
options.b = 1
options.c = 2
options.d = 3;
end
%%%%%%%%%%%%%%%%%%%%%%この部分をどのようにすればよいでしょうか%%%%%%%%%%%%%%%%%%%
obj = obj@ClassA(a, options); % エラー位置3の引数が無効です.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
obj.d = options.d;
end
end
end

回答 (0 件)

この質問は閉じられています。

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!