Download MetaTrader 5
To add comments, please log in or register
Trade with MetaTarder 5. Download it right now!
Ernie Gunning
1147
Ernie Gunning 2010.08.04 23:51 

I had the need to store different objects types (including value types) in one list or array. I struggled to do this in this c++ like language MQL5. How can I do this?

I needed something like this :

Object myObjects[10];
int point = 2;
string symbol = "Test";
myObject[0] = point;
myObject[1] = symbol;

This doesn't seem possible? My next alternative was to create a generic class...I'm afraid I might be hoping for the impossible? I don't see generics?

Luckily I managed to get past my problem but this was only because of my situation I'm in and I believe their might be people that want to do this??

Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Properties - Documentation on MQL5
Rashid Umarov
Admin
6599
Rashid Umarov 2010.08.04 23:57  
See Classes of data it may help you.

Paul
784
Paul 2010.08.05 05:40  
ToolMaker:

I had the need to store different objects types (including value types) in one list or array. I struggled to do this in this c++ like language MQL5. How can I do this?

I needed something like this :

Object myObjects[10];
int point = 2;
string symbol = "Test";
myObject[0] = point;
myObject[1] = symbol;

This doesn't seem possible? My next alternative was to create a generic class...I'm afraid I might be hoping for the impossible? I don't see generics?

Luckily I managed to get past my problem but this was only because of my situation I'm in and I believe their might be people that want to do this??

 

You seem to be looking for a 'Variant' data type like in Visual Basic.  This doesn't exist in C++ or MQL5, nor the legacy 'union' data construct from C days.  But it would be possible to code up what you're looking for in MQL5 if you write a number of very simple classes derived from CObject, and a generic Object array class derived from CArrayObj.  

Ideally operator overloading would make the resultant code as clean as your sample, but MQL5 unfortunately doesn't support it at this stage.

 Paul 

 

/
To add comments, please log in or register