How to assign struct references to variables?

If I have a struct array e.g. MyStruct[] that I access like MyStruct[2]

how can I take MyStruct[2] and put it into a variable maintaing the reference (not copying it)

so that instead of writing.

MyStruct[2].abc = 1;

MyStruct[2].def = 2;

I could write:

st = MyStruct[2]; // <------ does this copy or is it a reference? = 1; = 2;

also, how do you make a constructor to initialize a struct?

and also, if a struct contains a string - then it is intiialized - what does that mean? all zero’s out? like booleans are false, strings are “” ? numbers are 0?

MQL does not support reference variable (only params) and you cannot use pointers with structs (only classes), so the struct assignment is always a copy. That’s why I no longer use structs for anything and only use classes (unless I’m subclassing an MqlStruct to pass to an MqlFunction).

Also, you always need to initialize your members either in the initialization list or in the body of the constructor.

class MyClass {
   int abc;
   int def;
   MyClass():abc(0), def(0){}

now you can use pointers to accomplish your goal

MyClass objs[2];

MyClass *o1 = &objs[0]; = 10;

assert == objs[0].abc

thanks I’ll keep that in mind for the future, for me it is simpler just to leave my code as-is but good to know