Download MetaTrader 5

Passing a struct as argument into a function. Is it possible?

To add comments, please log in or register
Snelle Moda
648
Snelle Moda  

Hi.

I'm going to build a function (mqh) file which uses a lot of different variables and data types. Is it possible to combine these variables into a struct and pass the structure itself as a parameter into a function?

This example is not working.

void example(struct data) export
   {

   }


How can you exchange large numbers of different variables between custom indicators and scripts or EA's and scripts without using individual variables as argument in a function?

Thanks for help. 

Alain Verleyen
Moderator
35109
Alain Verleyen  

By reference only :

void example(struct &data) export
   {

   }

And you don't need "export" for an mqh file, only for compiled library (ex4).

Snelle Moda
648
Snelle Moda  

Hi Alain

Thanks for the help.

I get an error " '&' - struct can't be defined in parameters list"

How can I solve this error? See picture:


Xiangdong Guo
4379
Xiangdong Guo  
struct My_Stru {
  int i;
  string s;
}; 

void PassStructToMe(My_Stru &stru) {
  PrintFormat("i=%d, s=%s", stru.i, stru.s);
}
Snelle Moda
648
Snelle Moda  

Thank you all for the help.

It's working.

To add comments, please log in or register