有没有办法在类中使用预定义变量或使用起始值定义它? 我的代码:
TRoom = class(TObject)
private
pos: array[0..2] of integer;
up: TRoom;
right: TRoom;
down: TRoom;
left: TRoom;
--> freeSlots: array[0..3] of string = ('up','right','down','left'); <--
content: string;
end;
最佳答案
Is there a way to use a predefined variable inside a class or define it with a start value?
不可以,您不能为类的实例成员字段声明初始值。类默认初始化(即为零)。如果您想分配初始值,那么您应该在构造函数中执行此操作。
关于class - 如何在类声明中使用预定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70065136/