initializing an array with variable length?

To add comments, please log in or register
seravitae
94
seravitae  

Hey guys,

 Brand new to MQL4, been reading the docs and all that, so go easy on me!

 Just wondering if its possible to initialize an array with a variable length.

 

For instance, the following works fine:

 

double blah[10];

 

...Whereas this doesn't':

 

int arrayLength = 10;

double blah[arrayLength];

 

..returning: "integer number expected".

 

It seems to me that it should be trivial for MQL to support inheriting an array length via an integer variable, so I'm not sure why this behavior is present?

 

Kind regards,

Seb 

kolier1
120
kolier1  
double blah[];
int arrayLength = 10;
ArrayResize(blah,arrayLength);
ArrayResize() is the only solution for MT4.
seravitae
94
seravitae  

Ahh I see, thankyou kolier. Your answer is much appreciated!

 

Cheers,

Seb 

gordon
2325
gordon  
All arrays in MQL4 are static, hence they can only be initialized with a constant.
brewmanz
486
brewmanz  

a compromise might be

#define mysize 10
   double arr[mysize];
To add comments, please log in or register