I don't have a stackoverflow account so I'll have to answer here. What do you
think the output of the following code should be?
type
Person = object
id: int
name: string
proc newPerson(name: string): Person =
var next_id = 1
result.id = next_id
inc next_id
result.name = name
for p in ["Adam", "Billy", "Charlie", "David", "Eric"]:
echo newPerson(p).id
Run
If you thought it would print 1-5 then you need to brush up on your variable
scoping (newPerson resets the starting IDs to 1 and -1 each time it's called).
If you change your print function to print out the IDs of everyone you'll see
that all men share the same ID and all women share the same ID. If I were you I
would drop the ID bit altogether and simply compare objects directly, e.g.
personRef == other. If you fix your same-ID bug you'll run into other issues
though.