Download MetaTrader 5

passing struct array as function agrument

To add comments, please log in or register
Dua Yong Rew
5510
Dua Yong Rew  
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?

Alain Verleyen
Moderator
33339
Alain Verleyen  
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.;
}
Dua Yong Rew
5510
Dua Yong Rew  
angevoyageur:

There is no difference.

thanks, tried and works perfectly

any difference using 

double Distance(MqlRates &rates[])

 or

double Distance(MqlRates& rates[])
phi nuts
2181
phi nuts  
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.
Alain Verleyen
Moderator
33339
Alain Verleyen  
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.
Dua Yong Rew
5510
Dua Yong Rew  
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.
justaminute
5
justaminute  

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.

To add comments, please log in or register