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