instantiate objects from an array

Back to topics list To post a new topic, please log in or register
avatar
2
marksimmonds 2016.01.11 12:53
 

Hi,

I'm trying to create objects by looping through an array...... here's the code, but when I try to compile, I get the error "  '[' - invalid index error  "

Can somebody confirm if it can be done, and what I'm doing wrong

Thanks in advance.

//---Create Array of Symbols we wish to interogate
string Instruments[30] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CADJPY", "CHFJPY",
                      "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURTRY", "EURUSD",
                      "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDCAD", "NZDCHF",
                      "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY", "USDTRY"};
                      
//---CREATE CLASS STRUCTURE FOR SIGNALS

class PriceAction
  {
public:
   string name;
 };

for(int i=0; i < ArraySize(Instruments); i++)
     {
      PriceAction Instruments[i]();
      //Alert("New Object created:", Symbols[i].name);
     }
avatar
1109
Ovo 2016.01.11 13:06 #
 
Did you noticed you have Instruments declared twice? The second declaration is invalid, and moreover its live cycle is only within the current block.
avatar
12983
WHRoeder 2016.01.11 14:11 #
 
  1. Ovo: Did you noticed you have Instruments declared twice? The second declaration is invalid, and moreover its live cycle is only within the current block.
    If you had used #property strict, the compiler would have warned you about that.

  2. To create an array of objects the object must have a default constructor. See Structures and Classes - MQL4 Documentation. This you have since you didn't declare any constructors.
  3. You must do any other initialization in a method.

Back to topics list  

To add comments, please log in or register