Arrays are often used in C + + threads, and in the C + + programming version 2nd-rectification, it is also clear that the length of an array must be defined by a constant expression.
However, these two days because in the development of a C + + tool, suddenly found that C + + defines a one-dimensional array, you can also use variables to define the length.
ints=0;//number of rooms representedcout<<"Please input the number of rooms:"; CIN>>s; introbotnum=0;//represents the number of robotscout<<"Please input the number of robots:"; CIN>>Robotnum; intH=0;//number representing the conflict IDcout<<"Please input the number of conflict markings:"; CIN>>h; intm=robotnum*R; Ctree Tr[robotnum];
Part of the development code, the last line runs normally.
However, the use of more or dynamic arrays, because there are many structures in the project, there are arrays inside the structure, the length of the array is not certain, the array in the case of the dynamic open-up method.
struct ctnode{ int *M; int // The number of changes entering the node Ctnode *firstchild; *nextSibling; *parent;} Ctnode,*ctree;
The purpose of defining the pointer m is to create the array dynamically.
Ctree c=New ctnode;c->m=newint[s];
s can be any variable.
For a two-dimensional array, for example, create matrices out and in.
int** out,**inch; out=New int*[T]; inch=New int*[T]; for(intf=0; f<t;f++){ out[f]=New int[S]; inch[f]=New int[S]; }
This makes it possible to dynamically open up space without worrying about the length uncertainty.
C + + dynamic arrays