Download MetaTrader 5

Dynamic 2-Dimension Arrays

To add comments, please log in or register
Andriy Moraru
1261
Andriy Moraru  

How do I declare dynamic 2-dimension arrays?

The following code generates error:

int arr[][];
onewithzachy
2271
onewithzachy  
Andriy Moraru
1261
Andriy Moraru  
It hardly has anything to do with my question. It talks about initialization instead of declaring and says nothing about dynamic 2-dimension arrays.
onewithzachy
2271
onewithzachy  
enivid:
It hardly has anything to do with my question. It talks about initialization instead of declaring and says nothing about dynamic 2-dimension arrays.

Try this 

int qwerty [][2];

It's 2 dimensional array, the first bracket tell the array from left to right. the second bracket tell the array from top to bottom, and you have to specify how many of them - how many element of them.

Andriy Moraru
1261
Andriy Moraru  
onewithzachy:

Try this 

It's 2 dimensional array, the first bracket tell the array from left to right. the second bracket tell the array from top to bottom, and you have to specify how many of them - how many element of them.

Thanks, but that they only first dimension will be dynamic. I need both dimensions to be dynamic as I don't know the sizes beforehand.
investeo
4104
investeo  
enivid:
Thanks, but that they only first dimension will be dynamic. I need both dimensions to be dynamic as I don't know the sizes beforehand.
You can find an example in one of my articles - look at  https://www.mql5.com/en/articles/196 (CChartEditTable implementation)
Designing and implementing new GUI widgets based on CChartObject class
  • 2010.11.17
  • investeo
  • www.mql5.com
After I wrote a previous article on semi-automatic Expert Advisor with GUI interface it turned out that it would be desirable to enhance interface with some new functionalities for more complex indicators and Expert Advisors. After getting acquainted with MQL5 standard library classes I implemented new widgets. This article describes a process of designing and implementing new MQL5 GUI widgets that can be used in indicators and Expert Advisors. The widgets presented in the article are CChartObjectSpinner, CChartObjectProgressBar and CChartObjectEditTable.
Andriy Moraru
1261
Andriy Moraru  

investeo:
You can find an example in one of my articles - look at  https://www.mql5.com/en/articles/196 (CChartEditTable implementation)
Thanks! That's an interesting solution, but I doubt that I'll be able to use it with CopyBuffer() or even CopyArray()...
Rashid Umarov
Admin
12054
Rashid Umarov  
Andriy Moraru
1261
Andriy Moraru  
Looks interesting. Thanks! Too bad there's no intrinsic support for 2-dimension dynamic arrays though :-).
autotradefx
4
autotradefx  

 

Hi, I had the same problem, I'm just learning and I don't understand completely the solutions given, but this idea worked for me. I hope to help.

  struct dynamic_2D
      {
       double col[];
      };
   
   dynamic_2D u[];

   int nrow=10;
   int ncol=20;
   ArrayResize(u,nrow,0);
   for(int i=0; i<=nrow-1; i++) { ArrayResize(u[i].col,ncol,0); ArrayInitialize(u[i].col,0); }

 

To add comments, please log in or register