#Is there a way to instantiate a struct from a function but call a method on the struct before?
1 messages · Page 1 of 1 (latest)
Do you mean something like this?
var instance = Struct.init();
instance.someFunction();
return instance;
at the return address
You mean the result location? No, there is not currently a way to do that. If you want to init pointers into other fields of the same struct, you'll need to do a two-stage initialization where you first create the struct (eg withvar my_foo = Foo{}) and then initialize it in-place (eg. withmy_foo.init(), whereinittakes a*Foo)
If you don't have any self-referential pointers, QuantumDeveloper's answer should work fine
But since you specifically mentioned result locations, I'm guessing you do
ye, at least what this would do in a garbage collected language
is there some nice way to wrap this in a single function without using an allocator to create the struct?
no
well that would require what i asked in the first place lol