0
如何去分配一個對象的超類?賦值給一個超類
例子:
classdef foo < bar
...
methods
function this = barSet(this,b)
% Here I want to arrange that bar(this) == b
end
end
end
如何(或可以)我實現barSet
?
如何去分配一個對象的超類?賦值給一個超類
例子:
classdef foo < bar
...
methods
function this = barSet(this,b)
% Here I want to arrange that bar(this) == b
end
end
end
如何(或可以)我實現barSet
?
當弄亂基類時,應該使用@
-syntax(請參閱here)。例如:
classdef foo < bar
...
methods
function this = barSet(this,b)
%# call method in bar
[email protected](this, b);
...
end
end
end
方法barSet
在兩個foo
和bar
的方法。
這是延長重載方法的Matlab的方式:如果您在foo
省略barSet(this,b)
定義,要求
F = foo;
F.barSet(5);
會調用該方法barSet
在bar
類的說法5
。如果你定義它,該方法可以完全做其他事情,或者第一個做bar
中的版本,然後是更專門的東西(上面寫成'...'
)。
現在這樣做有幫助嗎?因爲我不清楚你想要什麼。我不明白你的意思是bar(this) == b
- 是b
foo
或bar
的一個實例?那你的意思是bar(this)
?複製構造函數?所以我正確理解你的意思,你的意思是你想用b
實例覆蓋this
實例嗎?
謝謝你看看這個。 您的建議要求我修改超類欄以添加方法barSet。我寧願避免以這種方式混淆超類。 我的意思是酒吧(這)(酒吧(這)== b)是這個類的酒吧演員。同樣,它的目的是讓b爲班級欄。 – lsfinn