problems with calloc

Hi everyone!

I'm trying to allocate memory for a matrix. I know the standard calloc use e.g

double *Sigma=(double *)calloc(2*Nxfm+2*Nyfm,sizeof(double));

My compiler doesn't let me to allocate in this way--> Matrix[numberrows][numbercolumns], so my question is, how can I allocate memory for a matrix using calloc?? If it is impossible, can anyone tell me what to do?

Thanks in advance!
If you want to access your matrix using the element access operator [], then you need to allocate the
matrix in the following way:

1
2
3
4
5
double** pMatrix = new double*[ Nyfm ];
for( size_t i = 0; i < Nyfm; ++i ) {
    pMatrix[ i ] = new double[ Nxfm ];
    // You'll want to zero out pMatrix[ i ][ 0 ] ... pMatrix[ i ][ Nxfm - 1 ] here
}


(You should use new instead of calloc if writing C++ code, though either one would work).
Thanks jsmith! Now I see the point.
Topic archived. No new replies allowed.