0

Are these two definitions equivalent?

type
  PersonObj = object
    name: string
    age: int
  PersonRef = ref PersonObj

type
  PersonObj = ref object
    name: string
    age: int

In the latter should PersonObj be simply called Person?

Facorazza
  • 317
  • 1
  • 15

1 Answers1

3

They are not equivalent as the first PersonObj is not ref, while the second is. To be equivalent the second definition should read as

type PersonRef = ref object
  name: string
  age: int

Now Obj or Ref suffixes is your own decision. Usually the suffixes are not used if the type is intended to be always used either as value type or a ref type, so it would be just:

type Person = ref object
  name: string
  age int
uran
  • 1,346
  • 10
  • 14
  • I think the question was whether the original `PersonRef` is equivalent to the second definition of `PersonObj`. – Yawar Oct 14 '18 at 05:29