T
Tom
Hi,
I am new in programming (and certainly in C++). I want to creat a
five-dimensional array. Two dimensions are numbers and other three are
variable.
One of the variables is an array whose dimension depends on one of the
remaing two variables. Can anyone give me some suggestion what I am
supposed to do?
What I did was the following:
.....
typedef struct {
int matrix[10][10];
} Name1;
....
main(){
...
int dim1; // variable dimension;
int* ar=new int[dim1];
int dim2; // variable dimension;
vector<vector<vector<Name1> > > aaa;
for(int i1=0;i1<dim2;i1++){
for(int i2=0;i2<dim1;i2++){
for(int i3=0;i3<ar[dim1];i3++){
for(int i4=0;i4<10;i4++){
for(int i5=0;i5<10;i5++){
aaa[i1][i2][i3].matrix[i4][i5]=a known 5d matrix
element;
}
}
}
}
}
delete[] ar;
}
However, when I compiled it always gave me a message Segmentation
fault (presumable this is an initialized issue, I am not sure as I
wrote before I am new in programming). My program compiles fine if I
remove the above segment.
Thanks in advance,
Tom
I am new in programming (and certainly in C++). I want to creat a
five-dimensional array. Two dimensions are numbers and other three are
variable.
One of the variables is an array whose dimension depends on one of the
remaing two variables. Can anyone give me some suggestion what I am
supposed to do?
What I did was the following:
.....
typedef struct {
int matrix[10][10];
} Name1;
....
main(){
...
int dim1; // variable dimension;
int* ar=new int[dim1];
int dim2; // variable dimension;
vector<vector<vector<Name1> > > aaa;
for(int i1=0;i1<dim2;i1++){
for(int i2=0;i2<dim1;i2++){
for(int i3=0;i3<ar[dim1];i3++){
for(int i4=0;i4<10;i4++){
for(int i5=0;i5<10;i5++){
aaa[i1][i2][i3].matrix[i4][i5]=a known 5d matrix
element;
}
}
}
}
}
delete[] ar;
}
However, when I compiled it always gave me a message Segmentation
fault (presumable this is an initialized issue, I am not sure as I
wrote before I am new in programming). My program compiles fine if I
remove the above segment.
Thanks in advance,
Tom