Download MetaTrader 5

function with array as return value? - page 2

To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
Fernando Carreiro
2349
Fernando Carreiro 2016.04.25 19:34  
Daysailor:

If i use you example I get an error message at the point where the function is supposed to return the Array. That error says "Invalid array access"

You cannot return an "Array". The example is flawed. It would make more sense like this:

void myFunction( double &theArray[] )
{
   for( int i = 0; i < ArraySize( theArray ); i++ )
   {
      theArray[ i ] = i + 10;
   }
}

Please note however, that the array is passed by reference, so that the original array is being directly modified!

If you need to keep the original and the "returned array" separate, you will have to make a copy of it before calling the function.

12
To add comments, please log in or register