Matlab无法调用超类方法
问题描述:
我是Matlab新手,面临调用超类方法的一些问题。Matlab无法调用超类方法
我有这样的代码:
超类测试1:
classdef test1 < handle
methods
function obj = test1()
end
function test2(obj)
disp(1);
end
end
end
子类测试:
classdef test < test1 & handle
properties
foo = 1;
end
methods
function obj = test()
obj = [email protected]();
end
function a = bar(obj)
superclasses(obj)
[email protected](obj)
end
end
end
继承正常工作;超类功能将test1
显示为test
的超类。然而,当我打电话[email protected](obj)
,它返回一个错误:
"@" Within a method, a superclass method of the same name is called by saying [email protected] The left operand of "@" must be the method name.
的test
2方法显然是超test1
中存在,所以我不知道究竟是怎么了。
答
只有当您的超类和子类中的方法名称相同且该调用位于具有相同名称的子类方法内时,才可以使用@语法。否则,您可以直接调用该方法,因为没有混淆。所以,而不是[email protected](obj)
只是使用test2(OBJ)。
您也不需要在子类中再次指定句柄作为超类。
是的,它现在有效。非常感谢! – user3245507