2011-09-16 55 views
5

基類有一個函數f。 派生類覆蓋函數f。 我想調用基類'f爲派生類的對象。我怎樣才能做到這一點?強制派生類在MATLAB中調用基函數?

以下是代碼示例。

classdef base 

     methods (Access = public) 
      function this = f(this) 
       disp('at base::f'); 
      end 

     end 
    end 

    classdef derived < base 

     methods (Access = public) 
      function this = f(this) 
       % HERE I WANT TO CALL base::f 
       [email protected](); % this is an error 

       disp('at derived::f'); 
      end 

     end 
    end 

d = derived(); 
d.f(); 
% here the result should be 
% at base::f 
% at derived::f 

回答

8

而不是

[email protected](); 

[email protected](this) 
+0

@Vahagn:它將disp已'在衍生:: F',因爲該聲明被調用到f @基地後執行。雖然我不明白無限循環。 – Jonas

+2

@Vahagn:以下是文檔中的鏈接:http://www.mathworks.com/help/techdoc/matlab_oop/bsa1q42.html – Jonas

相關問題