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

 

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. 

 

By reference only :

void example(struct &data) export
   {

   }

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

 

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:


 
struct My_Stru {
  int i;
  string s;
}; 

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

Thank you all for the help.

It's working.

Reason: