returning arrays

 
hi guys,

in a function I want to return an array:
int lala()
  {
    int lala[2] = {1,2};
    return(lala);
  }
alright, that works. However, how to put the returned var. into a new array?
double temp[] = lala();
That doesn't work :/.
Could anybody please tell me how I could get that working?
-
tradeigel
 
Try to use the ArrayCopy() function, please: https://docs.mql4.com/array/ArrayCopy
 
int lala(int& lala_arr[])
{
    ArrayResize(lala_arr,2);

    lala_arr[0]=1;
    lala_arr[1]=2;
    return(2);
}
int temp[];
int size=lala(temp);

https://docs.mql4.com/basis/variables/formal
 
alright, thank you very much...I'll try that later :)
 
@stringo: wait a minute, I can't return an array?!?!
If not, then I am really disappointed in MQL4. But I guess that can't be true.. .
And what does that '&' after the 'int' mean?

@tatyana: What do you mean? I think you can't use ArrayCopy to return an array, can you? ;)
 
see https://docs.mql4.com/basis/variables/formal - parameters passed by reference
 
oh, I see...with & you just pass the reference...Well, that works. However, is that really the common way to do it? I've never seen that in another language.
 
you can use '&' in c++ as well as returning arrays "int* function(){... return &array;}". Unfortunatelly MQL cant return arrays. but thanks god has '&' feature. My another disappointment in MQL it doesn't encapsulate variables properly - in loops for instance.
 
asmdev, Can you elaborate a bit on the problem of not encpsulating variables properly - in loops? I'm wondering if this is not part of my problem. I'm use to coding any language(Java,c#,etc); I'm new to MQL4 and attempting an indicator using trendlines mainly. I'm using mainly global arrays, resizing and modifying elements, passing them to userfunctions by reference. I find that I'm loosing control or track of variable values in loops especially if i'm iterating all the values along a trendline. I'm not getting the output expected. I try debugging and tracking variables in loops progressively but the results sometimes does not make any sense. Can you share further light on what you meant ealier?
 
for(int i = 0; i < 10; i++)
{
//Blah
}
int i = 0; //Error as i is already defined, this is not the case in C++, not sure about C.
All variables seem to have function scope.

The 2 things I would like to see in MQL are
1. A debugger
2. Structures
Reason: