0
我有一個節點類和一個樹類。我已經定義了節點類以包含節點聲明所需的屬性,並且樹類用於從節點形成樹結構。雖然樹結構是從節點形成的,但我在返回節點對象時遇到問題。我的代碼結構爲:通過第一類的構造函數返回第二個類的對象
classdef Node
properties
node_center;
node_size;
end
methods
function this = Node(center,size)
this.node_center = center;
this.node_size = size;
end
end
end % end of class Node
classdef Tree < handle
methods
function n = Tree(points,objects_in_tree)
n = Node(center_of_points,size);
n = insert_child(n,center,sizez);
end
end
現在我得到的錯誤是: 當構建類「樹」的一個實例,構造函數必須保留類返回的對象。 我知道爲什麼會發生這種情況的原因,但想知道解決此問題的方法。謝謝。