Download MetaTrader 5
To add comments, please log in or register
Interested in the Market activity? Come and track!
Eric Duran
160
Eric Duran 2011.01.12 08:11 

Hi I need to make an array in a procedure whose size is given by input arguments

void foo(int x, int y) {

 int A[x][y]; //Make a x-by-y array

 } 

 Doing it as shown gives an error.  It looks like you can only resize one dimension of a dynamic array with ArrayResize() ? Help!

Eric Duran
160
Eric Duran 2011.01.12 09:59  

Duck taped something together

 

class Int2DArray {

   int data[];
   int I, J;

   public:

   Int2DArray();
   ~Int2DArray();

   void put(int i,int j,int value);
   int get(int i,int j);
   void size(int rows, int colums);
   void printme();
   
};

void Int2DArray::Int2DArray(void) {

   //nothing

}

void Int2DArray::size(int rows,int columns) {

   I = rows;
   J = columns;

   ArrayResize(data,I*J);

}

void Int2DArray::~Int2DArray(void) {

   //nothing

}

int Int2DArray::get(int i,int j) {

   

   return data[j + i*J];

}

void Int2DArray::put(int i,int j,int value) {

   

   data[j + i*J] = value;

}

void Int2DArray::printme(void) {

   string poop = "";
   string s = "wave";
   
   for (int i = 0; i < I; i++) {
      for (int j = 0; j < J; j++) {
      
         StringAdd(poop," ");
         StringAdd(poop,get(i,j));         
      
      }
      Print(poop);
      poop = "";
   }

}

 

/
To add comments, please log in or register