Click here to Skip to main content
15,914,386 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am gettingfollowing warning message in my code:

$ g++ GES1.cpp
GES1.cpp: In function ‘int main(int, char**)’:
GES1.cpp:100:14: warning: deleting array ‘A’
delete [ ] A;

My code without the GaussElimination(....) function is:
C++
#include <iostream>
#include <cmath>
#include <fstream>
#include <ctime>
#include <vector>

#define n  3

using namespace std;


void GaussianElimination(double **,double *b ,double *y);
int main(int argc, char * argv[])
{
  /* values
  Row0 = 0, 2, 1; b0= -8
  Row1 = 1, -2, -3; b1 = 0
  Row3 = -1, 1, 2; b2= 3

  Ans = -4, -5, 2 */
  //int **A = new {{0.0, 2.0, 1.0, -8.0}, {1.0, -2.0, -3.0, 0.0},{-1.0, 1.0, 2.0,3.0}};
  
  
  double *A[n];
  for (int i=0; i < n; i++)
    A[i] = new double [n];
  double *b = new double[n];
  double *y = new double[n];
  
  A[0][0] =0.0;A[0][1] =2.0; A[0][2] = 1.0; //A[0][3] = -8.0;
  A[1][0] =1.0;A[1][1] =-2.0; A[1][2] =-3.0; //A[1][3] = 0.0;
  A[2][0] =-1.0;A[0][1] =1.0; A[0][2] = 2.0; //A[0][3] = 3.0;
  b[0] = -8.0;
  b[1] = 0.0;
  b[2] = 3.0;

  
  GaussianElimination(A, b ,y);
  delete [] y;
  delete [ ]b;
  for(int i = 0; i < n; i++)
    delete [] A[i];
  delete [ ] A;  
}

Some body please guide me.

Zulfi.

What I have tried:

Sorry I can't understand because I am using the same code in another program without any warning message.

Zulfi.
Posted
Updated 28-Apr-19 21:58pm
v2
Comments
[no name] 28-Apr-19 14:32pm    
Because there is no need to delete A?
Think again about your code:
for (int i=0; i < n; i++)
A[i] = new double [n];

and
for(int i = 0; i < n; i++)
delete [] A[i];


no need to delete A, because it never has been allocated and more it is simply a "stack variable".
zak100 28-Apr-19 14:59pm    
Good God bless you. Thanks for your quick response.
Zulfi.
[no name] 28-Apr-19 15:07pm    
I don't think God cares about such trivial things.
Bruno

double *A[n];
"A" is a variable you did not created dynamically, it is simply a variable. So why you think you can delete "A"?

See also my comment to your question.
 
Share this answer
 
v2
You misunderstood your A[] - it is an array of pointers, which you cant delete.

The best solution is:
C++
double A[n][n];
No need for additional allocations or deletes like 0x01AA correctly described.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900