I have a node class and a tree class. I have defined the node class to contain the properties needed for a node declaration and the tree class is used to form a tree structure from the nodes. While the tree structure is formed from the node, I am having a problem in returning the node object. My code structure is:
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
Now the error I am getting is: When constructing an instance of class 'Tree', the constructor must preserve the class of the returned object. I know the reason of why its happening but would like to know the workaround to this. Thanks.
The return value from the constructor must be the object created - there's no way around it. You can make another function that returns the other values (like the Node) that you would like to get out of it. After the Tree is constructed, call the accessor function on that object.