Nim如何定义构造函数?
Nim how to define constructors?
Nim 有没有办法为对象定义构造函数?
例如我有
type Deck* = ref object
cards* : array[52, Card]
我可以创建一个自动创建所有卡片的空构造函数吗?
type
Card = int
Deck* = ref object
cards* : array[52, Card]
proc newDeck: Deck =
new result
for i, c in result.cards.mpairs:
c = i
Nim 有没有办法为对象定义构造函数? 例如我有
type Deck* = ref object
cards* : array[52, Card]
我可以创建一个自动创建所有卡片的空构造函数吗?
type
Card = int
Deck* = ref object
cards* : array[52, Card]
proc newDeck: Deck =
new result
for i, c in result.cards.mpairs:
c = i