如果我有一个具有受保护属性的类,该类是该类的数组,并且有一个公共函数来获取该数组并返回它-我如何声明它,以便它允许该数组作为返回值?
通常,我会使用
TNodeArray = array of Node
方法,但是在这里不起作用。这就是我正在尝试的:
Node = class
protected
Neighbours : array of Node;
public
function GetNeighbours() : array of Node; //This is the problem line
end;
非常感谢收到任何帮助!谢谢!
将数组类型用作函数的参数或结果值的方法是使用不同的类型声明:
TNodeArray
在这里,您还必须向前声明Node
类以解析循环引用。
Type
Node = class; // Forward declaration of the class
TNodeArray = array of Node;
Node = class
protected
Neighbours : TNodeArray;
public
function GetNeighbours() : TNodeArray;
end;