我有 2 个类似的课程:
classdef class1 < handle
properties (Access = public)
b
end
properties (Access = private)
a
end
methods (Access = public)
function this = class1()
this.a = 1;
this.b = 1;
end
function test(this)
'Inside class'
this.a
this.b
this.a = 2;
this.b = 2;
end
end
end
第二个:
classdef class2
properties (Access = public)
b
end
properties (Access = private)
a
end
methods (Access = public)
function this = class2()
this.a = 1;
this.b = 1;
end
function test(this)
'Inside class'
this.a
this.b
this.a = 2;
this.b = 2;
end
end
end
有一次我从句柄继承。另一种我不做。在我创建这样的脚本之后:
solver1 = class1();
solver1.b
solver1
solver1.test()
solver1.b
solver1
solver1.test()
solver2 = class2();
solver2.b
solver2
solver2.test()
solver2.b
solver2
solver2.test()
如果我一步一步调试我的程序,我看到a和b在solver2.test()
. 但是第一堂课以后这些变量都变了solver1.test()
。这个问题的原因是什么?