我有一个抽象句柄类网格。它有几个具体的子类: Mesh1D , Mesh2D , Mesh3D 。我想编写一个函数,它对 Mesh1D , Mesh2D 和 Mesh3D 的影响微乎其微。因此,为了避免代码冗余,我正在考虑在超类中编写该函数,然后在子类中调用此函数。简化案例:
Mesh.m
classdef (Abstract) Mesh < handle
properties (Abstract)
prop;
end
methods (Abstract)
% Some abstract methods
end
methods
function assemble(obj, other_parameters)
% Do something
end
end
end
Mesh1D
classdef Mesh1D < Mesh
properties
prop;
% Other properties
end
methods
function assemble(obj)
% Preprocessing steps
assemble@Mesh(other_parameters) % call the superclass method
% Postprocessing steps
end
end
但是,它会产生错误:'assemble' is not an accessible method of base class 'Mesh'.
有什么问题?