请看下面的代码:
Ex_ObjA.m
classdef Ex_ObjA
properties
a
end
methods
function Obj=Ex_ObjA(t)
Obj.a = t;
end
end
end
Ex_ObjBC.m
classdef Ex_ObjBC
properties
b
end
properties (Dependent = true, SetAccess = public)
c
end
methods
function Obj=Ex_ObjBC(t)
Obj.b = t;
end
function c=get.c(Obj,s1) % error: Get methods must have exactly one input
c = Obj.b + s1.a;
end
end
end
我尝试执行以下操作:
s1 = Ex_ObjA(2);
s2 = Ex_ObjBC(3);
s2.c
不成功,因为"Get 方法必须只有一个输入"。所以我可以通过s1.a
toEx_ObjBC
来获得s1.c
?