强制派生类在MATLAB中调用基函数?

时间:2011-09-16 12:53:50

标签: oop matlab inheritance virtual-functions

基类具有函数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

1 个答案:

答案 0 :(得分:8)

而不是

this@base.f();

它是

f@base(this)