If you want it initialized, you must do it.
If you want it initialized, you must do it.
Wrong. You have been told twice, now three times.
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
I just have got a new problem. hope you guys solve this.
suppose I have this
struct x { int y[]; int z; };
then I declare struct as array
x test[];
If I want to create some function calling test[]
like this
void func (.... &test[])
{
}
this is my question
1.What is prefix or type of &test[]? What type should I fill in this(....)?
2.how to access the member of arraystruct (there are 2 y[] and z) in the function when I pass array with struct ?
thank you again
I just have got a new problem. hope you guys solve this.
suppose I have this
then I declare struct as array
If I want to create some function calling test[]
like this
this is my question
1.What is prefix or type of &test[]? What type should I fill in this(....)?
2.how to access the member of arraystruct (there are 2 y[] and z) in the function when I pass array with struct ?
thank you again
I would suggest this option:
//+------------------------------------------------------------------+ //| Test_en.mq5 | //+------------------------------------------------------------------+ struct Sx { int y[3]; int z; //--- Constructor Sx() { ArrayInitialize(y,1); z=2; } //--- Destructor ~Sx() { } }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { Sx test[]; ArrayResize(test,3); //--- func(test,2); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void func(Sx &struct_array[],int index) { int size=ArraySize(struct_array); if(index>=0 && index<size) { Print(IntegerToString(struct_array[index].y[0])); Print(IntegerToString(struct_array[index].z)); } } //+------------------------------------------------------------------+
result:
2019.10.23 12:19:14.419 Test_en (EURUSD,H1) 1 2019.10.23 12:19:14.419 Test_en (EURUSD,H1) 2
x test[];1.What is prefix or type of &test[]? What type should I fill in this(....)?
2.how to access the member of arraystruct (there are 2 y[] and z) in the function when I pass array with struct ?
You agree to website policy and terms of use
Hi experts,
I am confused about these code. I have tried to create array in struct.Those initial value should be "0" in all array.
but why not?How does it come from?
in my opinion, it should be
0
0 0
0 0 0
0 0 0 0
0 0 0 0 0
Could anyone please help
thank you