Download MetaTrader 5
To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
Mihai Ionescu
1250
Mihai Ionescu 2010.09.28 12:47 

I read here: https://www.mql5.com/en/docs/basis/variables/formal

and here: https://www.mql5.com/en/docs/basis/function/functionoverload

and this code is supposed to be valid:

double AverageFromArray(const int array[],int startPos = 0, int endPos = -1) {
   int size = ArraySize(array);
   if(size<=0) return 0.0;
   
   if (endPos < 0) endPos=size-1;
   else if (startPos > endPos) return 0.0;
   
   double sum=0.0;
//---
   for(int i=startPos;i<=endPos;i++) sum+=array[i]; 
   double aver=sum/(endPos-startPos+1);
//---
   //Print("Calculation of the average for an array of double type");
   return aver;
  }

 But compiler throws:  'array' - arrays are passed by reference only.

If I remember well, at some point there was a decision to pass arrays only as reference to be able to send fixed length arrays as formal parameters.

I don't know if I'm right. But if this is the case, then documentation has to be changed, right?

It's not thaaat important anyway, but it gets confusing when you copy paste the example and then you get errors. 

--- 

(this version with const int array[] was attractive, because of naming problems (formal array name coinciding with a global variable name, and then errors))

Documentation on MQL5: Language Basics / Variables / Formal Parameters
  • www.mql5.com
Language Basics / Variables / Formal Parameters - Documentation on MQL5
Rashid Umarov
Admin
11555
Rashid Umarov 2010.09.28 13:12  
ifmihai:

I read here: https://www.mql5.com/en/docs/basis/variables/formal

and here: https://www.mql5.com/en/docs/basis/function/functionoverload


I don't know if I'm right. But if this is the case, then documentation has to be changed, right?

You are right. Help was fixed, thank you.
Mihai Ionescu
1250
Mihai Ionescu 2010.09.28 15:20  
Rosh:
You are right. Help was fixed, thank you.
Glad to be helpful
/
To add comments, please log in or register