Error when using get method (MATLAB:class:DependentGet)
3 次查看(过去 30 天)
显示 更早的评论
Consider the following Class and the short script to build the blocks of a table. The idea behind the script is that T stands for the whole table where as U and V are two subblocks, constituting the table. Why does Matlab throw this error when I query V.top?
In class 'TestComponent', the get method for Dependent property 'top' attempts to access the stored property value. Dependent properties don't store a value and can't be accessed from their get method.
Script:
T = TestComponent
U = TestComponent
V = TestComponent
T.add(U)
T.add(V)
V.top
Class:
classdef TestComponent < handle
properties
Children
previousPeer
topRoot = 1
height = 1
end
properties (Dependent)
top
end
methods
function val = get.top(obj)
if ~isempty(obj.previousPeer)
val = obj.previousPeer.top + obj.previousPeer.height;
else
val = obj.topRoot;
end
end
function add(obj,child)
if isempty(obj.Children)
obj.Children{1} = child;
else
child.previousPeer = obj.Children{end};
obj.Children{end + 1,1} = child;
end
end
end
end
0 个评论
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!