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

Vah*_*agn 5 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
Run Code Online (Sandbox Code Playgroud)

Jon*_*nas 8

代替

this@base.f();
Run Code Online (Sandbox Code Playgroud)

它的

f@base(this)
Run Code Online (Sandbox Code Playgroud)

  • @Vahagn:这是文档中的链接:http://www.mathworks.com/help/techdoc/matlab_oop/bsa1q42.html (2认同)