强制派生类调用 MATLAB 中的基函数?
基类有一个函数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
[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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是
它
Instead of
it's