私は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
そして2番目:
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()
プログラムを段階的にデバッグすると、 の後の 2 番目のクラスで a と b が変更されていないことがわかりsolver2.test()
ます。しかし、これらの変数が変更された最初のクラスはsolver1.test()
. この問題の理由は何ですか?