I have a "class" type like this:
type
Question = object
what: string
answer: int
When I instantiate a Question object the default way I get
$ echo Question()
(what: "", answer: 0)
How can I change the declaration to another default value for answer?
I tried
type
Question = object
what: string
answer = 42
But then the compiler complains with "Error: initialization not allowed here"
Nim currently does not have default values for constructors. You could use my package made for generating constructors to quickly make a proc that does as such.
import constructor/construct
type
Question = object
what: string
answer: int
Question.construct(true):
answer = 42
assert initQuestion() == Question(answer: 42)