Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Pascal-如何从类中的函数返回类的数组?_Arrays_Function_Class_Return_Pascal - Fatal编程技术网

Arrays Pascal-如何从类中的函数返回类的数组?

Arrays Pascal-如何从类中的函数返回类的数组?,arrays,function,class,return,pascal,Arrays,Function,Class,Return,Pascal,如果我有一个类,它有一个受保护的属性,即该类的一个数组和一个公共函数来获取该数组并返回它-我如何声明它以便它允许该数组作为返回值 通常我会使用 TNodeArray = array of Node 方法,但这在这里不起作用。这就是我正在尝试的: Node = class protected Neighbours : array of Node; public function GetNeighbours() : array of Node; //This is th

如果我有一个类,它有一个受保护的属性,即该类的一个数组和一个公共函数来获取该数组并返回它-我如何声明它以便它允许该数组作为返回值

通常我会使用

TNodeArray = array of Node
方法,但这在这里不起作用。这就是我正在尝试的:

Node = class
  protected
     Neighbours : array of Node;
  public
     function GetNeighbours() : array of Node; //This is the problem line
end;

感谢您的帮助!谢谢大家!

将数组类型用作参数或函数结果值的方法是使用distinct type声明:

TNodeArray
这里还必须向前声明
节点
类,以便解析循环引用

Type

  Node = class;  // Forward declaration of the class

  TNodeArray = array of Node;

  Node = class
    protected
     Neighbours : TNodeArray;
    public
     function GetNeighbours() : TNodeArray; 
  end;

抱歉-只是澄清一下,节点也会有其他属性。再次感谢您使用
TNodeArray
@LURD替换类中节点声明的
数组-谢谢!但是,如果我将TNodeArray声明为节点的数组-我不能链接它,可以吗?如果我在Node类之前声明TNodeArray,那么它将不会初始化,因为它还不知道节点是什么。如果在节点类之后声明,那么getNeights():TNodeArray将无法工作,因为它不知道TNodeArray是什么。再次感谢你的帮助!是的,请参阅下面我的答案如何转发声明
节点
类以解析循环引用。