passing struct array as function agrument

 
double   Bar_Close[];

double Distance(double& Bar_Close[])
{
...
}

for double I know it pass like above

but how about this?

MqlRates Bar_Rates[];

how can I pass the array as an argument into the function?

 
doshur:

for double I know it pass like above

but how about this?

how can I pass the array as an argument into the function?

There is no difference.

MqlRates Bar_Rates[];

double Distance(MqlRates &rates[])
{
//---

   return 0.;
}
 
angevoyageur:

There is no difference.

thanks, tried and works perfectly

any difference using 

double Distance(MqlRates &rates[])

 or

double Distance(MqlRates& rates[])
 
doshur:

thanks, tried and works perfectly

any difference using 

 or

What the compiler and debug says ?, if it's fine, than its OK.

Old post with old build of MT5 https://www.mql5.com/en/forum/631

(Bug) Functions that returns struct
(Bug) Functions that returns struct
  • www.mql5.com
The compilation goes with no error, but the code simply doesn't run, no error alert of any kind, the code simply does nothing.
 
doshur:

thanks, tried and works perfectly

any difference using 

 or

There is no difference, but I prefer the first as the reference (&) is related to the variable and has nothing to do with the type.
 
phi.nuts:

What the compiler and debug says ?, if it's fine, than its OK.

Old post with old build of MT5 https://www.mql5.com/en/forum/631

no error either way. guess it should be ok.
 

I am passing a reference to MqlRates and using this in my class.

However when I try to save this reference as I use it many times in the class, I get an error. Is there a solution to store a reference?

MyClass

private MqlRates myrates[];

Public:
void SetMyRates(MqlRates rates[]){myrates = rates;} //Attempting to store the reference fails


I can use the reference in the array directly, but is there a solution for storing the reference in my class for repeated use? Thank you.

 

How can pass MqlRates like this, is this possible?

MqlRates rates[];

Function(rates[].open, rates[].high, rates[].low, rates[].close);

Thank you very much for your answer.

 
MqlRates rates_original[];

void test_function(MqlRates &reference[])
{
int total=ArraySize(reference);
if(total>0) Print("Open : "+reference[0].open);
}

reference may be confusing , think of it as "telling the function which rates array to read"

void runtest()
{
ArrayResize(rates_original,5,0);
rates_original[0].open=1.25;
test_function(rates_original);//telling it where to read from
}
 
Alain Verleyen: There is no difference, but I prefer the first as the reference (&) is related to the variable and has nothing to do with the type.

And I prefer the other way; a variable that is a reference to a type. Sixty (60) years since C first came out; still no consensus.

Reason: