Error 4007 in insert values of an array to other array

 

hello 

i want to insert values of an array to other array

my code:

void OnStart()
  {
  int g[]={1,3};
  int l[]={4,5};
  insert(g,l);
  ArrayPrint(g);
  ArrayPrint(l);
  
  }
//+------------------------------------------------------------------+


void insert(int &array1[],int &array2[])
{
int size1=ArraySize(array1);
int size2=ArraySize(array2);
ArrayResize(array1,size1+size2);
for(int i=0;i<size2;i++)
{
array1[size1+i]=array2[i];
}

}

But the ArrayResize dont work and its output is ERROR 4007

i use ((sizeof)) to know size of my arrays and i get 52!

please help me what can i do for my function?

 
Amini1382: But the ArrayResize dont work and its output is ERROR 4007

Perhaps you should read the manual. ArrayResize - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

  int g[]={1,3};
If ArrayResize() is applied to a static array, a timeseries or an indicator buffer, the array size remains the same – these arrays will not be reallocated. In this case, if new_size<=ArraySize(array), the function will only return new_size; otherwise a value of -1 will be returned.
 
William Roeder #:

Perhaps you should read the manual. ArrayResize - Array Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

thanks for your answer .

do you have a solution for my idea?(insert values of an array to other array)

 
Amini1382 #: do you have a solution for my idea?(insert values of an array to other array)

Stop using a static array. When in doubt, think!

  int g[]={1,3};
  int l[]={4,5};
  int both[];  insert(both,g);  insert(both,l);
Reason: