基类拥有函数f。派生类重写了函数f。我想为派生类的对象调用基类的函数f。我该怎么做?
以下是代码示例。
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
this@base.f(); % 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
derived::f
,因为该语句在对f@base的调用之后执行。不过我不理解无限循环。 - Jonas