you have to pass the by reference...
string a[3]; returnArray(a); print(a[0]); void returnArray(string& a[]){ a[0] = "A"; a[1] = "B"; a[2] = "C"; }
you have to pass the by reference...
Hey thanks, I didn't know you could referance variables. Do you know where I can find any documentation on that? Does the "&" statement mean to referance? Aslo, the a[] parameter, I thought you always had to put a size in the array declaration (a[3]) or else it wouldn't work. What does a[] mean? Blaaaa
probably in the book somewhere https://book.mql4.com//
Yes the & sign is many languages used for reference params.
In general that is true. But since you are passing by reference the the var is already be decleared somewhere. in this case "string a[3]" To make the example more explainatory
string gsText[3]; returnArray(gsText,0); print(gsText[1]);// prints B gsText[1] = "foo"; returnArray(gsText,1); print(gsText[1]);// prints foo void returnArray(string& rsText[], int iRun){ if (iRun == 0){ rsText[0] = "A"; rsText[1] = "B"; rsText[2] = "C"; } }
gsText
g = global
s = string
rsText
r = return
so rsText is really a pointer to gsText. But a C programmer can explain this stuff far better I guess
hth
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can Arrays be passed and returned as parameters in custom functions?
I try this and it doesn't work:
string someArray = returnArray();
OR
string someArray;
ArrayCopy( someArray, returnArray() );
string returnArray()
{string a[3];
a[0] = "A";
a[1] = "B";a[2] = "C";
return(a);}
Any tips?