In R2018b, I have the following setup:
classdef SomeClass < handle
methods
function SomeMethod(obj)
disp in!
end
end
end
classdef SomeOtherClass < handle
properties (Constant)
instance = SomeClass()
end
methods
function Test(obj)
hdl = @obj.instance.SomeMethod;
hdl();
end
end
end
However, running the Test()
method gives an error:
>> SomeOtherClass().Test()
Undefined function or variable 'obj.instance.SomeMethod'.
Changing the Test()
method to:
function Test(obj)
A = obj.instance;
hdl = @A.SomeMethod;
hdl();
end
gives the desired result:
>> SomeOtherClass().Test
in!
I'm puzzled...why do I need the middle man A
?