Hi I have tried several times to create Getter and Setter methods in my project but failed.
The code is this:
var Frank : Human
Frank = Human(age: 67) echo Frank.age ("This works)
getAge(Frank, age) ("This does not work")
How do I create a Getter and a Setter method to set the age of the Frank object?
You might also wants to do this the Nim way
proc age(a: Human): int = a.age
proc `age=`(a: var Human, age: int) =
a.age = age
Frank.age = 99 # or `age=`(Frank, 99)
echo Frank.age # or age(Frank)
Note: if the age field can be accessed directly, then Nim will prioritize that instead.