Download MetaTrader 5

Array of References or Pointers to Objects (Structs)

To add comments, please log in or register
Post web links to other trader's signals and make profit
Carl Schreiber
6610
Carl Schreiber 2014.03.09 11:16 

In the reference of MQL4 I find the basic DataTypes and I can define array of theses types but a reference or pointers to structs is not mentioned there.

Can I define an array of references to e.g. struckts and how should I do this?

An array of handles has to be defines as an array of int.

Gooly

Ex Ovo Omnia
3156
Ex Ovo Omnia 2014.03.09 11:31  

I do not think so. It makes structure nearly useless for OOP. The predefined structures like MqlRates are very difficult to handle without pointers/references.

I convert them 1:1 to objects, despite it consumes resources and time.

Objects have no problem.

Carl Schreiber
6610
Carl Schreiber 2014.03.09 11:33  
Ex Ovo Omnia
3156
Ex Ovo Omnia 2014.03.09 11:37  
gooly:
I'll ask the service desk..
If you ask them "how", they will froward you here and/or give you a link to docs.
Carl Schreiber
6610
Carl Schreiber 2014.03.09 11:45  

Well this works so far:

void OnStart()  {
//---
   struct TradeSet {
        string symb;// = "xxxYYY"; // GBPUSD   
   };
   TradeSet arr[3];
   int i;
   for(i=0;i<3;i++){
      arr[i].symb = "Test "+(string)i; 
   }
   string x;
   for(i=0;i<3;i++){
      x = x+"\n"+arr[i].symb;
   }
   Comment(x);
}

But I'd like to initialize the string-values but the compiler refuses this :(

Carl Schreiber
6610
Carl Schreiber 2014.03.09 11:53  
Ovo:
If you ask them "how", they will froward you here and/or give you a link to docs.

Well in the ref is nothing about this way of using :(
Ex Ovo Omnia
3156
Ex Ovo Omnia 2014.03.09 12:15  
gooly:

Well this works so far:

But I'd like to initialize the string-values but the compiler refuses this :(

I am not sure, what you mean by "initialize string-values". This?

   struct TradeSet {
      TradeSet() : symb("xxxYYY"){}
        string symb;// = "xxxYYY"; // GBPUSD   
   };

or

TradeSet arr[] = {{"x"},{"y"},{"z"}};
Carl Schreiber
6610
Carl Schreiber 2014.03.09 13:05  

Normal variables I can initialize at their definition:

int x = 1;

And I would prefer to be able to do this as well:

 struct TradeSet {
        string symb = "xxxYYY"; // GBPUSD   
   };

But your way is the intention and may be the only way.

Gooly

To add comments, please log in or register