Pascal-如何从该类中的函数返回一个类的数组?

问题描述 投票:0回答:1

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

通常,我会使用

TNodeArray = array of Node

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

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

非常感谢收到任何帮助!谢谢!

arrays function class return pascal
1个回答
0
投票

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

TNodeArray

在这里,您还必须向前声明Node类以解析循环引用。

Type

  Node = class;  // Forward declaration of the class

  TNodeArray = array of Node;

  Node = class
    protected
     Neighbours : TNodeArray;
    public
     function GetNeighbours() : TNodeArray; 
  end;
© www.soinside.com 2019 - 2024. All rights reserved.