Download MetaTrader 5

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

To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
Snelle Moda
602
Snelle Moda 2016.02.17 17:43 

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
30731
Alain Verleyen 2016.02.17 17:58  

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
602
Snelle Moda 2016.02.17 18:05  

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
3740
Xiangdong Guo 2016.02.17 18:45  
struct My_Stru {
  int i;
  string s;
}; 

void PassStructToMe(My_Stru &stru) {
  PrintFormat("i=%d, s=%s", stru.i, stru.s);
}
Snelle Moda
602
Snelle Moda 2016.02.17 21:29  

Thank you all for the help.

It's working.

To add comments, please log in or register