Download MetaTrader 5

Initialize struct array

To add comments, please log in or register
Unable to find the answer to your question? Use the search!
Alexandra
230
Alexandra 2014.07.31 19:37 
struct MyStruct
{
  double a, b, c, d;
};

 MyStruct upper[]; 
ArrayResize(upper,100);

ArrayInitialize(upper,EMPTY_VALUE);
   Is there a way struct array Initialize ?
Alain Verleyen
Moderator
30752
Alain Verleyen 2014.07.31 21:23  
Freitag:
   Is there a way struct array Initialize ?

Yes by adding a constructor to your struct. When you will use ArrayResize the constructor will be called for each element of the array.

  MyStruct() : a(EMPTY_VALUE),b(EMPTY_VALUE),c(EMPTY_VALUE),d(EMPTY_VALUE) {};
Alexandra
230
Alexandra 2014.08.01 07:23  
Thanks.
To add comments, please log in or register