Dynamic 2-Dimension Arrays

 

How do I declare dynamic 2-dimension arrays?

The following code generates error:

int arr[][];
 
It hardly has anything to do with my question. It talks about initialization instead of declaring and says nothing about dynamic 2-dimension arrays.
 
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.

 
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.
 
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.
 

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()...
 
 
Looks interesting. Thanks! Too bad there's no intrinsic support for 2-dimension dynamic arrays though :-).
 

 

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); }

 

 
Andriy Moraru:

How do I declare dynamic 2-dimension arrays?

The following code generates error:

Hello Andriy,

The multidimensional arrays are dinamic "ONLY" at the first dimension...

Take a look at the article about arrays...

MQL5 PROGRAMMING BASICS: ARRAYS

https://www.mql5.com/en/articles/567

Hope it helps...


If you need dinamic on more than 1 dimension, you will need to create a code with "for example" struct... Like autotradefx showed up this...

Fundamentos básicos da programação MQL5: arrays
Fundamentos básicos da programação MQL5: arrays
  • www.mql5.com
Juntamente com as variáveis e funções, os arrays são partes integrais de quase todas as linguagens de programação. Muitos programadores iniciantes frequentemente ficam com medo dos arrays. Parece estranho, mas é verdade! Posso assegurar que eles não são nem um pouco assustadores. Na realidade, os arrays são semelhantes às variáveis comuns. Sem...
Reason: