Board index » cppbuilder » using of delete for **arrays: double** C = new double* [azei]:???????????????????

using of delete for **arrays: double** C = new double* [azei]:???????????????????


2003-09-16 09:16:28 PM
cppbuilder45
Hi, I have written the following procedure for Multiplication of two arrays
A,B with an new array C, but Idon'nt knw how to delete C:
double **produkt(double *A[],int azei,int asp,
double *B[],int bzei,int bsp)
{
double** C = new double* [azei];
for (int i = 0;i<=azei;i++)
{
C[i] = new double[bsp]; /////////////<<<<<------definition of the
array
}
for (int j=1;j<=bsp;j++)
{
for(int i=1;i<=azei;i++)
{
C[i][j]=0.0;
for (int k=1 ; k<=asp;k++)
{
C[i][j] +=A[i][k]*B[k][j];
}
}
}
return C; //////////////<<<<<<<<<<<<<<-----return to main program
}
after calling this routine in the main program I have to delete array C
before I can use the routine again. but how to do this???
That can't be right:
main()
{
D=produkt(E,F,3,4,4,5)
delete[ ] C ?????????? ////////////<<<<<--------deleting of the array
??????????
....................
}
 
 

Re:using of delete for **arrays: double** C = new double* [azei]:???????????????????

"Peter Jahn" < XXXX@XXXXX.COM >wrote in message
1) for each members of D
delete [] D[x]
2)
delete [] D;
 

Re:using of delete for **arrays: double** C = new double* [azei]:???????????????????

"Peter Jahn" < XXXX@XXXXX.COM >writes:
[Your immediate question has already been answered.]
Quote
Hi, I have written the following procedure for Multiplication of two arrays
A,B with an new array C, but Idon'nt knw how to delete C:

double **produkt(double *A[],int azei,int asp,
double *B[],int bzei,int bsp)

{
double** C = new double* [azei];
for (int i = 0;i<=azei;i++)
{
C[i] = new double[bsp]; /////////////<<<<<------definition of the
array
}
Please note that you are going to lose resources if these new expressions
fail. I'd use objects rather than a "raw" pointers for expressing the
ownership of all these dynamically allocated objects.
 

{smallsort}