1)不 this 与函数句柄无关,这是用于调用超类构造函数的语法
2)你可以试试看自己。这是一个例子:
是
classdef A < handle
properties
a = 1
end
methods
function obj = A()
disp('A ctor')
end
end
end
BM
classdef B < A
properties
b = 2
end
methods
function obj = B()
obj = obj@A(); %# correct way
%#obj = A(); %# wrong way
disp('B ctor')
end
end
end
使用正确的语法,我们得到:
>> b = B()
A ctor
B ctor
b =
B with properties:
b: 2
a: 1
如果您使用注释行而不是第一行,则会收到以下错误:
>> clear classes
>> b = B()
A ctor
A ctor
B ctor
When constructing an instance of class 'B', the constructor must preserve the class of the returned
object.
Error in B (line 8)
disp('B ctor')