Why can use this function with only on input?

2 visualizaciones (últimos 30 días)
fa wu
fa wu el 25 de Jul. de 2023
Comentada: fa wu el 26 de Jul. de 2023
Form this document ,need”Google Web Translation“
there is two class AcListSuper AcListNonSub
AcListSuper.m
classdef AcListSuper
methods (Access = {?AcListNonSub})
function obj = m1(obj)
disp ('Method m1 called')
end
end
end
AcListNonSub.m
classdef AcListNonSub
methods
function obj = nonSub1(obj,AcListSuper_Obj)
% Call m1 on AcListSuper class
AcListSuper_Obj.m1;
end
function obj = m1(obj)
% Define a method named m1
disp(['Method m1 defined by ',class(obj)])
end
end
end
creat two object a b
a = AcListSuper;
b = AcListNonSub;
When I run this,program will call" function obj = nonSub1(obj,AcListSuper_Obj)" ,but this function has two input,“b.nonSub1(a);" just give one input! function "nonSub1" has no input test like "nargin" ………… ,but there is no erro waring!
I run this program and tracking to "AcListNonSub.nonSub1",I found "obj" class is "AcListNonSub" , "AcListSuper_Obj" class is "AcListSuper" .
Why? b.nonSub1(a) just give one input , AcListNonSub.nonSub1 automatically assigned two classes to “obj” and “AcListSuper_Obj” ?
According to what rules does MATLAB assign input parameters?
b.nonSub1(a);

Respuesta aceptada

Steven Lord
Steven Lord el 25 de Jul. de 2023
b.nonSub1(a) just give one input
Incorrect. As shown in the "Dot and Function Syntaxes" section on this documentation page this is not equivalent to calling nonSub1 with just a as input. It is equivalent to nonSub1(b, a) in almost all circumstances. [The case where it doesn't is if the class of a lists the class of b as one of its InferiorClasses, as discussed on this documentation page and the "Determining Which Method Is Invoked" section on the first documentation page to which I linked.]

Más respuestas (0)

Categorías

Más información sobre Construct and Work with Object Arrays en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by