我想在这样的抽象类中定义一个具有属性的接口 classdef A properties (Abstract = true) Valid; endend 像这样的这个接口的实现 classdef B A properties (Dependent = true) Valid; end methods function v = get.Valid(obj
classdef A properties (Abstract = true) Valid; end end
像这样的这个接口的实现
classdef B < A properties (Dependent = true) Valid; end methods function v = get.Valid(obj) v = 1; end end end
但是当我尝试制作B的实例时,我得到以下错误
>> c = B() ??? Error using ==> B The property 'Valid' restriction defined in class 'B' must match the property definition in base class 'B'.
谁能告诉我我做错了什么?
尝试在基类中设置Dependent属性:classdef A properties (Abstract = true, Dependent = true) Valid; end end
根据documentation:
Concrete subclasses must redefine abstract properties without the
Abstract attribute set to true
我理解这一点的方式,子类属性属性必须与基类匹配(没有Abstract属性)