I tried to do a search but it's not helpful (the forum search should look in the titles first)
type Example = ref object
a:seq[string]
var anExample:Example
proc function(ex:Example, txt:string) =
ex.a.add(txt) # " SIGSEGV: Illegal storage access. (Attempt to read from nil?) "
function(anExample, "Hello")
for i in anExample.a:
echo i
I try to find what I'm doing wrong.
since Example is a ref object, it default initialises to nil. You need to initialise it:
type Example = ref object
a:seq[string]
# you can change it from var to let and still modify the memory the reference is pointing to,
# though not reassign the pointer
let anExample = Example()
proc function(ex:Example, txt:string) =
ex.a.add(txt)
function(anExample, "Hello")
for i in anExample.a:
echo i