2012-08-07 45 views
4

我想在抽象類定義與性質的接口這樣如何獲得抽象的依賴特性的工作

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 

但是當這種接口的實現我試圖讓一個BI的實例得到以下錯誤

>> c = B() 
??? Error using ==> B 
The property 'Valid' restriction defined in class 'B' must match the property definition in base class 'B'. 

有誰可以告訴我做錯了什麼?

回答

1

嘗試設置Dependent屬性屬性在基類,以及:

classdef A 
    properties (Abstract = true, Dependent = true) 
     Valid; 
    end 
end 

按照documentation

具體的子類必須沒有 摘要屬性設置爲true

重新定義抽象屬性

我明白這一點,子類親perty屬性必須與基類匹配(不包含Abstract屬性)

+0

謝謝,這確實解決了這個問題。我想我沒有提到_...中的'Dependent'屬性,而沒有將Abstract屬性設置爲true,並且必須使用與SetAccess和GetAccess屬性相同的值作爲基類。 – Windancer 2012-08-07 20:52:34