arrays - Pascal - 如何从该类中的函数返回一个类的数组?
问题描述
如果我有一个类,它具有一个受保护的属性,该属性是该类的一个数组和一个公共函数来获取该数组并返回它 - 我如何声明它以便它允许该数组作为返回值?
通常我会使用
TNodeArray = array of Node
方法,但这在这里行不通。这就是我正在尝试的:
Node = class
protected
Neighbours : array of Node;
public
function GetNeighbours() : array of Node; //This is the problem line
end;
任何帮助都感激不尽!谢谢!
解决方案
使用数组类型作为参数或函数结果值的方法是使用 distinct 类型声明:
TNodeArray
在这里,您还必须转发声明Node
类以解析循环引用。
Type
Node = class; // Forward declaration of the class
TNodeArray = array of Node;
Node = class
protected
Neighbours : TNodeArray;
public
function GetNeighbours() : TNodeArray;
end;
推荐阅读
- javascript - 如何在css中悬停时更改光标大小
- javascript - if 语句将 url 的特定字母或短语与设置的字符串进行比较
- node.js - Mongoose 聚合排序和查找限制
- jupyter-notebook - Jupyter Notebook 代码都默认为大写
- java - 将 log4j2 日志重定向到 java.util.logging
- regex - 如何在spark sql中提取where子句作为数组?
- php - 如何将表行返回到现有变量?
- javascript - ReactJS 组件落后于 Navbar
- node.js - Firebase 托管 + 自定义服务器不兼容?
- ios - 重置领域云中所有领域的架构