Force derived class to call base function in MATLAB?
Asked Answered
S

1

5

Base class has a function f. Derived class overwrites the function f. I want to call base class' f for an object of the derived class. How can I do this?

Here is the code sample.

    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
Serial answered 16/9, 2011 at 12:53 Comment(0)
A
8

Instead of

[email protected]();

it's

f@base(this)
Afforest answered 16/9, 2011 at 13:16 Comment(2)
@Vahagn: It will disp at derived::f, since that statement gets executed after the call to f@base. I don't understand the infinite loop, though.Afforest
@Vahagn: Here's the link in the documentation: mathworks.com/help/techdoc/matlab_oop/bsa1q42.htmlAfforest

© 2022 - 2024 — McMap. All rights reserved.