2

使用定义为的类型type BroTuple = distinct tuple[a, b, c: int],我如何:

  • 创建一个新实例(Brotuple()告诉我Error: object constructor needs an object type

  • 访问其字段(proc example(br: BroTuple) = echo br.aError: undeclared field: 'a':)

4

1 回答 1

2

使用不同的元组有点奇怪,因为它的目的distinct是隐藏您通常拥有的访问器和过程。如果您的目标是防止与其他元组/对象产生歧义,则应该使用对象。

如果你真的想要它,你可以去:

type BroTuple = distinct tuple[a, b, c: int]

var bro = BroTuple((a: 0, b: 0, c: 0))
echo((tuple[a, b, c: int])(bro).a)
于 2015-06-29T16:57:25.880 回答