Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用定义为的类型type BroTuple = distinct tuple[a, b, c: int],我如何:
type BroTuple = distinct tuple[a, b, c: int]
创建一个新实例(Brotuple()告诉我Error: object constructor needs an object type)
Brotuple()
Error: object constructor needs an object type
访问其字段(proc example(br: BroTuple) = echo br.a说Error: undeclared field: 'a':)
proc example(br: BroTuple) = echo br.a
Error: undeclared field: 'a'
使用不同的元组有点奇怪,因为它的目的distinct是隐藏您通常拥有的访问器和过程。如果您的目标是防止与其他元组/对象产生歧义,则应该使用对象。
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)